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

Assign values to Constant in SAS

 

How to assign required constant value for required variables:

Ex:

Data. Trt;

Pid = 100;

Drug = ’col 5 mg’;

Sdate = ‘12oct2003’d;

Stime=’13:23:34’t;

Ed time =’14dec2003; 10:12:23’dt;

Run;

Proc print data =trt;

Format sdate word date 18.

Stime  time8.

Edate  date time 18.;

run;

ex;

/* extraction */

Data one;

Infile ‘d:\medi.txt’;

Input pid drug $;

Run;

/* transformation and loading*/

Data medi;

Set one;

Group =’G100’; -> constant value loading

If drud = ‘col 5 mg’

Then u date =’12 oct 2006’d;

Else If drud = ‘col 10 mg’

Then u date =’12 oct 2006’d +30;

Else u date =’12 oct 2006’d +60;

Format  udate date 9;

Run;

Proc print data =medi;

Run;

Capture

 

 

Learn the core features of SAS and become master with our expertise SAS Training and Placement.

Do while loop: data generating:

Ex:

Data demo;

i=100;

dowhile (i<=120);

pid = I; output;

i =i+1;

End;

Drop i;

Run;

Proc print data =demo;

Run;

 

Do until loop:

Ex:

Data demo;

i=100;

do until(i>120);

pid = I; output;

i =i+1;

End;

Drop i;

Run;

Proc print data =demo;

Run;

Ex:

Data demo;

i=100;

do while (i<=150);

pid = I; output;

i=i+2;

End;

Drop i;

Run;

Proc print data =demo;

Run;

Do loop, work like a do while loop but we can write all loop requirements in single statement.

Ex:

Data demo;

Do i =100 to 150 by 2;

pid = I; output;

End;

Drop i;

Run;

Proc print data =demo;

Run;

 

Data reading; single trail method:

     Using single trail method we can hold the SAS system at the end of the SAS session. But we can’t run trail methods multiple times.

Ex:

Data medi;

Input pid visit drug $ @; output;

Input visit drug $ @ ; output;

Input visit drug $ @ ; output;

Input visit drug $ @ ; output;

Cards;

100  1  5mg  2  5mg  3  10 mg  4  15 mg

100  1  10mg  2  10mg  3  15 mg  4  15 mg

;

Proc print data = medi;

Run;

(or)

Data medi 1;

Input visit drug $ @ ; output;

Do i= 1 to 3;

Input visit drug $ @ ; output;

End;

Drop i;

Cards;

100  1  5mg  2  5mg  3  10 mg  4  15 mg

100  1  10mg  2  10mg  3  15 mg  4  15 mg

;

Proc print data = medi;

Run;

Ex:

Data medi;

Input pid drug $ @ ; output;

Do i= 1 to 2;

Input drug $ @ ; output;

End;

Drop i;

Cards;

1  col 5 mg     col10 mg     col 15 mg

2  col 5 mg     col10 mg     col 15 mg

10  col 5 mg     col10 mg     col 15 mg

Run;

Proc print data = medi;

Run;

For indepth knowledge on SAS, click on below

Summary
Review Date
Reviewed Item
Assign values to Constant in SAS
Author Rating
5

“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 Assign values to Constant 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.