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

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

 

IDJan_17Feb_17Mar_17Apr_17May_17Jun_17Jul_17Aug_17Sep_17Oct_17Nov_17Dec_17Jan_18Feb_18Mar_18Apr_18May_18Jun_18Jul_18Aug_18Sep_18Oct_18Nov_18Dec_18
37386412-9-322012-2229-4-18-19-30-7-343027411-2330-35-25-11-40813
39343814-27-5-13-3526148-28-38103237-17-3222232427-822-21-1413

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 

IDStatus
37386412Mar_17
39343814May_17

 

Kindly help me on this.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Update

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 863 views
  • 3 likes
  • 2 in conversation