Hi,
I want to write an array for creating a new column where copying column header in row on basis of observations, like I have a data set which has 24 variables and now I want to know which column has provided me the values >0 first time for example
ID | Jan_17 | Feb_17 | Mar_17 | Apr_17 | May_17 | Jun_17 | Jul_17 | Aug_17 | Sep_17 | Oct_17 | Nov_17 | Dec_17 | Jan_18 | Feb_18 | Mar_18 | Apr_18 | May_18 | Jun_18 | Jul_18 | Aug_18 | Sep_18 | Oct_18 | Nov_18 | Dec_18 |
37386412 | -9 | -32 | 20 | 12 | -22 | 29 | -4 | -18 | -19 | -30 | -7 | -34 | 30 | 27 | 4 | 11 | -23 | 30 | -35 | -25 | -11 | -40 | 8 | 13 |
39343814 | -27 | -5 | -13 | -35 | 26 | 14 | 8 | -28 | -38 | 10 | 3 | 23 | 7 | -17 | -32 | 22 | 23 | 24 | 27 | -8 | 22 | -21 | -14 | 13 |
in the above case for Id 37386412 Mar_17 is providing >0 value first time and for Id 39343814 May_17 is providing >0 value first time, so like wise my new column will be like this
ID | Status |
37386412 | Mar_17 |
39343814 | May_17 |
Kindly help me on this.
I assume that ID is character, so the array is easy to create
data want;
set have;
array arr{*} _numeric_;
do i=1 to dim(arr);
if arr[i]>0 then do;
Status=vname(arr[i]);
return;
end;
end;
keep ID Status;
run;
I assume that ID is character, so the array is easy to create
data want;
set have;
array arr{*} _numeric_;
do i=1 to dim(arr);
if arr[i]>0 then do;
Status=vname(arr[i]);
return;
end;
end;
keep ID Status;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.