Contributor
Posts: 20

# Explicit output statement - how is this data step working?

[ Edited ]

data new;

x=10;

y=20;

output;

z=50;

output ;

x=100 ;

output ;

run;

what is the output? and how? I am not able to solve this question, can someone help me out?

Super User
Posts: 2,078

## Re: Base SAS

why not run it and let all of us know

Contributor
Posts: 20

## Re: Base SAS

yes, can run it and know the answer, but i m not able to understand how this output came. I want to understand the procedure. Anyway output is given below -

x y z
10 20 .
10 20 50
100 20 50

Super User
Posts: 2,078

## Re: Base SAS

Sorry mate!, I am not keen on doing a tutorial. You can forgive me or hate me lol. Anyway, I am sure somebody else will.

@Reeza  and @MichelleHomes posted brilliant ideas/links to get you(hmm us) started in this link

Free learning resources

Super User
Posts: 10,623

## Re: Base SAS

An output statement does not change any variable values, so the previously set values persist. Only a skip into the next iteration of a data step would set variables to missing.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 93

## Re: Base SAS

In the given code you have 3 outputs right then it will give you 3 observations if you have 10 output statements then it will give you 10 observations.

firs toutput iteration: x,y have values and z is missing you given output statement so it will print values for x,y and z for missing.

secondoutput iteration:z have value 50 so it will print z with 50 and you already ave x,y values so in second iteration it will print 10,20 as x,y values

third output iteration: x,y,z contain values but you again assigned with 100 x value over write and y,z values as follows.

data new;

x=10;

y=20;

output;

z=50;

output ;

x=100 ;

output ;

run;

Contributor
Posts: 20

## Re: Base SAS

Thanks very much..

Super User
Posts: 9,866

## Re: Base SAS

If that solved your problem, please mark @rajeshalwayswel as the correct answer.  For future information, it is a good idea to run things, use tutorials and such like.  Your question is very simple and running the code should explain what output you get.

Super User
Posts: 10,623

## Re: Base SAS

And by all means, use more descriptive subjects for future posts. Base SAS in the Base SAS Programming community is, pardon my wording, not very intelligent.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 24,028

## Re: Base SAS

[ Edited ]

Key ideas:

• explicit OUTPUT
• when are variables reset

data new;

x=10; <- sets x to 10

y=20; <- sets y to 20

output; <- outputs record to data set

z=50; <- sets z to 50

output ; <- outputs record to data set. Since x/y have not been changed they remain the same

x=100 ;<- sets x to 100.

output ; <- outputs record to data set. Since y/z have not been changed they remain the same

run; <- data step boundary - all variables are reset but since no other instructions the data step is terminated.

Note that I've modified the subject line of your post to make it more descriptive. There are too many 'BASE SAS' questions.

Ankur32 wrote:

data new;

x=10;

y=20;

output;

z=50;

output ;

x=100 ;

output ;

run;

what is the output? and how? I am not able to solve this question, can someone help me out?