DATA Step, Macro, Functions and more

SAS Output

Reply
Occasional Contributor
Posts: 10

SAS Output

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;

PROC Star
Posts: 1,577

Re: SAS Output

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;

Occasional Contributor
Posts: 10

Re: SAS Output

Posted in reply to novinosrin

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

PROC Star
Posts: 1,577

Re: SAS Output

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. 

Super User
Posts: 6,631

Re: SAS Output

[ Edited ]

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.

Ask a Question
Discussion stats
  • 4 replies
  • 123 views
  • 0 likes
  • 3 in conversation