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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 448 views
  • 3 likes
  • 2 in conversation