BookmarkSubscribeRSS Feed
Ankur32
Obsidian | Level 7

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?

 

thanks in advance

9 REPLIES 9
novinosrin
Tourmaline | Level 20

why not run it and let all of us know 

Ankur32
Obsidian | Level 7
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

novinosrin
Tourmaline | Level 20

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

 

 

 

Kurt_Bremser
Super User

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.

rajeshalwayswel
Pyrite | Level 9

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;

 

 

Ankur32
Obsidian | Level 7

Thanks very much.. 🙂

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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.

Reeza
Super User

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?

 

thanks in advance


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 9 replies
  • 1830 views
  • 4 likes
  • 6 in conversation