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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.