BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
novinosrin
Tourmaline | Level 20

Nothing is too much. I love these questions Gonna go out for lunch to give farewell to my classmate who just graduated. Will respond after lunch(Chicago time).Hang in there. Cheers

novinosrin
Tourmaline | Level 20

@new_sas_user_4

 

The set statement reads one record into a memory area known as program data vector that holds the observation while datastep is executed
So when set have executes for the 1st time
A 10 100 1
is read into memory and is held for further processing i.e using other statements that
follows set statement
Now let's get into the loop.
The index variable n when 1,
references the 1st element of the array as j(n)<=>income
Inc_rain_snow=vname(j(n));
this resolves to Inc_rain_snow=vname(j(1))
and that is Inc_rain_snow=vname(income);
similarly
value=j(n);
resolves to value=j(1); and that is value=income;
the rest of the variable values remain undisturbed and the output statment writes the
contents in the memory to the output dataset. The same happens for 3 iterations as we loop through
the 3 elements in the array. So the output statement executes thrice within the loop writing the
value of area A thrice.

Once SAS has executed all the statements for the 1st records, the process repeats for the next record
until end of file as it goes back to the top of the datastep.

new_sas_user_4
Quartz | Level 8

Thank you so much @novinosrin for taking the time to explain this 🙂

I got it 🙂

Tom
Super User Tom
Super User

Why do you need to change the order of columns?

The normal SAS "trick" to changing the order of the columns is to use a RETAIN statement, since it does not imply a type.  

data want;
   retain _name_ area col1 ;
   set have;
run;

Or you could use PROC SQL.

proc sql;
  create table want as 
  select 
 _name_
, area
, col1
  from have
  ;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 18 replies
  • 22156 views
  • 5 likes
  • 3 in conversation