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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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