BookmarkSubscribeRSS Feed
unnati
Obsidian | Level 7

I would like to know that how SAS read OUTPUT option in following code.I know this will add '99' into each observation into trt01an variable and 'all' into each observation into trt01 variable. 

I would like to know how SAS read this and how PDV take value  and how it read.

 

can Anyone explain this ?

 

data ab;

    set cd;

  output;

    trt01an=99;

    trt01='all';

 output;

run;

4 REPLIES 4
novinosrin
Tourmaline | Level 20

At compliation:

SAS reads the descriptor portion of the input dataset in the set statement and creates Pdv initialising all vars+assignment new vars to missing

At execution:

data ab;

    set cd;

  output; /*first explicit out writes all values+ assignment new vars with missing to output dataset*/

    trt01an=99;

    trt01='all';

 output;/*2nd explicit out writes all values+ new vars with assigned with 99 and 'all' to output dataset*/

run;

unnati
Obsidian | Level 7

i would like to know that how SAS Read data step and put 99 and all under each and every observation. Can you please explain me in more detail. 

Capture.JPG

novinosrin
Tourmaline | Level 20

you wrote-" Can you please explain me in more detail."

 

Ok, the two vars are apparently in coming from your input dataset. So basically after reading the values from the input dataset, sas resets the value of those two vars with new values assigned during each iteration of the dataset. I hope this helps

 

Nevertheless, my explanation may still be inadequate as I lack the style and art of explaining concepts. Please do wait for other responses and choose your pick. 

Astounding
PROC Star

The DATA step statements execute in order.

 

OUTPUTmeans take whatever is there now, and copy it to the output data set.

 

So, the first OUTPUT statement takes copy of the observation from CD, and outputs it without change.

 

Then the assignment statements execute, assigning values to TRT01 and TRT01AN.

 

Then the final OUTPUT statement executes, copying the current values for all variables to the output data set.

 

So with two OUTPUT statements, each incoming observation appears twice in the output data set.  The first OUTPUT statement does not reflect the assignment statements, but the second one does.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1411 views
  • 0 likes
  • 3 in conversation