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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2496 views
  • 2 likes
  • 2 in conversation