/* dataset */
_NAME_ new1 new2 new3 new4
Time_0 1 2 3 4
Time_1 5 6 7 8
Time_2 9 10 11 12
Time_3 13 14 15 16
I have a dataset, and need to use a two-dimensional array - temprg{i,j} for some data manipulation.
how to assign value to this array?
Most online SAS tutorials use Datalines, but since I have much more rows and columns, I'm looking for another way to assign the initial values. e.g. temprg{2,3} would be 7. temprg{4,2} would be 14.
Thanks.
Since you don't post your data in the form of a sas data set, I presume you want to make an array out of 4 observations. Then what do you want to do? Do you want to generate a collection of results for every 4 incoming rows? if so, you can start with this:
data _null_;
array temprg {0:3,4};
array new {4};
do row=0 to 3;
set have;
do col=1 to 4; temprg{row,col}=new{col}; /*temprg{row}=new{col};*/ end;
end;
** Now use the array to generate results **;
run;
BTW, I've indexed the rows as 0 to 3, not 1 to 4. Since you have _NAME_=0,1,2,3.
Since you don't post your data in the form of a sas data set, I presume you want to make an array out of 4 observations. Then what do you want to do? Do you want to generate a collection of results for every 4 incoming rows? if so, you can start with this:
data _null_;
array temprg {0:3,4};
array new {4};
do row=0 to 3;
set have;
do col=1 to 4; temprg{row,col}=new{col}; /*temprg{row}=new{col};*/ end;
end;
** Now use the array to generate results **;
run;
BTW, I've indexed the rows as 0 to 3, not 1 to 4. Since you have _NAME_=0,1,2,3.
Data step 'arrays' don't function like they would in IML, ie no tranpsose or inverting them via functions, only via looping manually.
I really think your logic is simple if you took the time to state it out. I'm not going to try and decipher it though.
When referencing a two dimensional array, you need two indexes. I think this corrects the issue.
temprg{row, col}=new{col};
If you matrix functionality I suggest using SAS IML instead of Base.
What are you trying to do ? Reeza is absolutely right. Use IML code if you want some matrix operator.
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.