• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Tracking variables creations and temporary variable creation in SAS

Tracking variables creations and temporary variable creations:

Using this concept, we can report matching observation or non matching observation from required data set. Tracking variable can be created by in option. If tracking variable value is 1 we get matching variable, if tracking variable value is 0 we get non matching variable.

/* To report each and every patient SBP information with drug information after taken the treatment*/

Capture

 

 

 

 

 

 

 

 
Data trt;

Infile ‘d:\trt.txt’;

Input pid drug $sbp;

Cards;

Data suc;

Infile ‘d:\sucess.txt’;

Input pid sbp;

Cards;

Data fail;

Infile ‘d:\fail.txt’;

Input pid sbp;

Cards;

Proc sort data =txt;

By eid;

Run;

Proc sort data =suc;

By eid;

Run;

Proc sort data =fail;

By eid;

Run;

To import the data are txt, suc, fail. Sorting the 3 data sets based on matching variables.

/* To update txt with suc*/

Data txt;

Update txt suc (in = var);

By pid;

If var =1 then statue =’sucess’;

Run;

/* To update txt with fail*/

Data txt;

Update txt fail(in = var);

By pid;

If var =1 then statue =’failure’;

If status = ‘ ‘ then

Status = ‘change’;

Proc print data =txt;

Run;

These core tutorials will help you to learn the Tracking variable creations and temporary variable creation in SAS. 
For an in-depth understanding and practical experience,  explore SAS Training Online.

Modify statement:

It can be used to replace the data values (from update the data values) manipulating data, delete observations, modifications.

  • Modification can be done by using set statement or modify statement
  • Using set statement we can do modifications in existed data set using expressions.
  • Using modify statement we can do modification in existed data set using expressions and another data set values.

Ex:

Data emp;

Input eid salary ;

Cards;

100  4000

101  8000

;

/* use with set */

Data emp;

Set emp;

Salary =salary +1000;

Run;

/* use with modify*/

Data emp;

 

Set emp;

Run;

Proc print data =emp;

Run;

Note:

Using set statement we can do modifications and these modifications can be stored in new variable and new data set or existed variable and existed data set.

Using modify statement we can do modifications and these modifications can be stored in existed data set or existed variable.

/*To do modification in one data set to another data set */

Syntax:

Modify <master file> <transition file>;

By <matching variable>;

Ex:

Data emp;

Input eid salary  ;

Cards;

100  3000

101  2000

102  4000

;

Data emp1;

Input eid   bonus;

Cards;

100  500

102  1000

101  200;

Proc sort data = emp1;

By eid;

Run;

Data emmp;

Modify emp emp1;

By eid;

Salary =salary +bonus;

Run;

Proc print data =emp;

Run;

/* To reporting patient SBP after taken the treatment drug information */

Ex:

Data medi;

Input stno drug$ sbp;

Cards;

100 col5mg 156

101 col5mg 159

102 col10mg156

103 col10mg145

104 col15mg167

;

Data success;

Input stno srate :percent3;

Cards;

100  50%

102  40%

100  30%

;

Data fail

Input stno frate : percent 3.;

Cards;

101  20%

104  10%

;

Proc sort data =medi;

By stno;

Run;

Proc sort data =success;

By stno;

Run;

Proc sort data =fail;

By stno;

Run;

/* To modify medi use with success*/

Ex:

data medi;

Modify medi success;

By stno;

Sbp= sbp * srate;

Run;

/* To modify medi use with fail*/

Ex:

data medi;

Modify medi fail;

By stno;

Sbp= sbp+(sbp *frate);

Run;

Proc print data =medi;

Run;

 

/* To replace the master data set values with transition file using modify statement*/

Ex:

Data emp;

Input eid salary  ;

Cards;

100  5000

101  4000

;

Data emp1;

Input eid   nsal;

Cards;

101  7000

100  6000

;

Proc sort data = emp;

By eid;

Proc sort data = emp1;

By eid;

Run;

Data emp;

Modify emp emp1;

By eid;

Salary =n sal;

Run;

Proc print data =emp;

Run;

Case 1:

      Non matching observation (non obs) occurred in master file we can run the modify statement.

Case 2:

      Non matching observation (non obs) occurred in transition we can’t run the modify statement(modify statement does not have appending capability).

Capture

Case 3:

      Non matching variable occurred in master file, we can run the modify statement.

Case 4:

Non matching variable occurred in transition file, we can’t run the modify statement.

For indepth knowledge on SAS, click on below

Summary
Review Date
Reviewed Item
Tracking variables creations and temporary variable creation in SAS

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Tracking variables creations and temporary variable creation in SAS"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.