BookmarkSubscribeRSS Feed
pablorodriguez1
Calcite | Level 5

 

I have a data set with ID in rows and months in columns, as the one shown below.

 

I want to create an auxiliary column that records the first value that is not zero of each line.

 

IDM1M2M3M4M5 Auxiliary column
100887 8
2777.. 7
300009 9
409998 9
511111 1
602211  

 

Currently l am using this code, but I haven't been able to get the results I am looking for. Any ideas?

data new_ops04;     
set new_ops03;

array MONTHS (24) M1-M24;

RETAIN AUXILIARY_COLUMN 0;
	do i=1 to 24;
	IF MONTHS(i) ne 0 and AUXILIARY_COLUMN = 0 THEN
               AUXILIARY_COLUMN = MONTHS(i);
	end;
		drop i;
run;

 

Thanks a lot!

1 REPLY 1
art297
Opal | Level 21
data new_ops04;     
  set new_ops03;

  array MONTHS (24) M1-M24;

  do _n_=1 to 24;
    IF MONTHS(_n_) gt 0 THEN do;
      AUXILIARY_COLUMN = MONTHS(_n_);
      leave;
    end;
  end;
run;
 

Art, CEO, AnalystFinder.com

 

sas-innovate-2024.png

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.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 2282 views
  • 2 likes
  • 2 in conversation