BookmarkSubscribeRSS Feed
SachinRuk
Calcite | Level 5
hi all,

some help?

data newtable;
do i=1 to 5;
y_i.=i;
end;
run;


I want to keep the variables y_1, y_2 and so on (not i)

thanks in advance,
Sachin
4 REPLIES 4
Rambo
Calcite | Level 5
You could initialize an array with the name of the variables that you want.

For example, you could have said array y_(5); Then you reference the array like so in the data step: y_(i) = value;. When the array is stored in the dataset, it will actually be stored as y_1, y_2, etc.

Note; In the array statement, the number in parentheses tells sas how many elements you need in your array; for you example, it should match the number of iterations in the do loop.
Cynthia_sas
SAS Super FREQ
And, this is a very good introduction to ARRAY processing and ARRAY concepts in SAS:
http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf

cynthia
SASPhile
Quartz | Level 8
Try this:




%macro sachin;
data newtable;
%do i=1 %to 5;
%let j=&i.;
y_&j.=&j.;
%end;
run;
%mend sachin;
%sachin;
SASPhile
Quartz | Level 8
Applying Rambo's suggestion:


data newtable1;
array y_(5);
do i= 1 to 5;
y_(i)=i;
end;
drop i;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 858 views
  • 0 likes
  • 4 in conversation