BookmarkSubscribeRSS Feed
KarolineN
Obsidian | Level 7

Dear SAS Community,

I am having an issue with SAS that I have not experienced before when multiplying two variables. When I conduct the following calculation: 

 

data dataset_2;
Ser_Occ=_FREQ_*Ntot;
set dataset_1;
run;

 

I get this result: 

KarolineN_0-1597916430743.png

I do not understand why the values of the resulting new varibale "Ser_Occ" are shifted one row down. That is, the result of the calculation of row 1, is displayed in row 2, and so on. I would like to get the result of the calculation in the same row.

I would be very grateful for some feedback from you on why SAS studio does this and how to get the values in the same row? Could it for example have to do with the settings or the underlying format of _FREQ_ which was computed using proc summary statement? 

 

Best regards,

Karoline

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Your screen capture is too small to read. Can you please provide the data as just plain old text and paste it into your message so we can read it?

--
Paige Miller
Kurt_Bremser
Super User
data dataset_2;
Ser_Occ=_FREQ_*Ntot;
set dataset_1;
run;

The read of a dataset occurs where you wrote the SET statement; since you do your calculation before the read, it uses the values from the previous observation (or missing values in the first observation).

Keep in mind that, by definition, all variables from input datasets are automatically retained, so not set to missing at the beginning of a data step iteration.

KarolineN
Obsidian | Level 7

Thank you very much @Kurt_Bremser. I see the problem and now understand how the placement of the code (before/after) the set statement makes a difference!

 

Best regards, Karoline

Kurt_Bremser
Super User

The nice thing about a (basically) interpreter language is that you can quickly test such minor code changes and inspect the results for the effects. See Maxim 4.

And such tinkering lets you gain an insight into the mechanics of the data step, which may be overwhelming at first, but offer a VERY wide field of options to the developing SAS hacker.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 522 views
  • 2 likes
  • 3 in conversation