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

@TLSAS Please test the below and let me know. I am here at my college lab for two more hours to  make any further changes if needed:

 

data a;
    input id mon $2. month11 $2. month12 $2. month13 $2. month14 $2. month15 $2. month16 $2.;
    datalines;
1 12 c c c c c n
2 10 c c n n c n
3 13 n n c c n n
4 12 c n c n c c
;
run;

data b;
set a;
array t(*) month:;
do _n_=1 to dim(t)-1;
if mon=substr(vname(t(_n_)),anydigit(vname(t(_n_))))  and t(_n_)='c' and t(_n_+1)='c' then enroll=1;
end;
run;
TLSAS
Fluorite | Level 6

Thanks @novinosrin! This works well.

 

I was trying to use substr but it didn't work, and you always know what works. Amazing. Thanks!

novinosrin
Tourmaline | Level 20

@TLSAS We are a team. Have fun. I am gonna sleep.I have my finals exam for this quarter mon and wed next week. Might be slow in my response. But keep your questions coming. Have fun and take care

AnnaBrown
Community Manager

Hi @TLSAS,

 

I'm glad you found some useful info! If one of @novinosrin's replies was the exact solution to your problem, can you "Accept it as a solution"? Or if one was particularly helpful, feel free to "Like" it. This will help other community members who may run into the same issue know what worked.

Thanks!
Anna


Join us for SAS Community Trivia
SAS Bowl XXIX, The SAS Hackathon
Wednesday, March 8, 2023, at 10 AM ET | #SASBowl

TLSAS
Fluorite | Level 6

@AnnaBrown

 

I marked the solution!

 

Thanks,

 

TLSAS
Fluorite | Level 6

Hi Novinosrin,

 

Thank you for your reply.

 

I used the macro because I always got the error message with the %do statement (see bellow).

 

For output dataset b, I want to create a binary variable that equal to 1 whenever the variable "mon" has the value that equal to the suffix of the variable "month1-month2".

 

Is that clear to you?

 

 



ERROR: The %DO statement is not valid in open code.
240
241  %do i=1 %to &max.;
242      call symputx('mon1',"month"||compress(mon));
         ----
         180

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
  • 20 replies
  • 1786 views
  • 8 likes
  • 3 in conversation