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

Hello,

I would like to use macro variables, but I am not comfortable.

I have a number changing column cond_i from one time to another.

I would like a macro variable that counts the cond_i collones.

To allow to do

 

if cond_1 to cond_ & i = F then Top = 1 elce Top = 0

 

Thanks for your idea

 

Table      
IDNameCond_1Cond_2Cond_3Cond_4 
1tomF    
2arthurFFFF 
3didier F F 
4françoisFFFF 
5harryFFF  
       
Want      
IDNameCond_1Cond_2Cond_3Cond_4Top
1tomF   0
2arthurFFFF1
3didierFFFF0
4françoisFFFF0
5harryFFF 0
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Why does row 3 get the F's filled in? How is that logic defined?

 

Otherwise, you need arrays not macros. 

 

data want;
set have;
array cond(*) cond_1-cond_4;
top = 1;

do i=1 to dim(cond);
     if cond(i) ne 'F' then top=0;
end;

run;

@WilliamB wrote:

Hello,

I would like to use macro variables, but I am not comfortable.

I have a number changing column cond_i from one time to another.

I would like a macro variable that counts the cond_i collones.

To allow to do

 

if cond_1 to cond_ & i = F then Top = 1 elce Top = 0

 

Thanks for your idea

 

Table            
ID Name Cond_1 Cond_2 Cond_3 Cond_4  
1 tom F        
2 arthur F F F F  
3 didier   F   F  
4 françois F F F F  
5 harry F F F    
             
Want            
ID Name Cond_1 Cond_2 Cond_3 Cond_4 Top
1 tom F       0
2 arthur F F F F 1
3 didier F F F F 0
4 françois F F F F 0
5 harry F F F   0

 

View solution in original post

2 REPLIES 2
Reeza
Super User

Why does row 3 get the F's filled in? How is that logic defined?

 

Otherwise, you need arrays not macros. 

 

data want;
set have;
array cond(*) cond_1-cond_4;
top = 1;

do i=1 to dim(cond);
     if cond(i) ne 'F' then top=0;
end;

run;

@WilliamB wrote:

Hello,

I would like to use macro variables, but I am not comfortable.

I have a number changing column cond_i from one time to another.

I would like a macro variable that counts the cond_i collones.

To allow to do

 

if cond_1 to cond_ & i = F then Top = 1 elce Top = 0

 

Thanks for your idea

 

Table            
ID Name Cond_1 Cond_2 Cond_3 Cond_4  
1 tom F        
2 arthur F F F F  
3 didier   F   F  
4 françois F F F F  
5 harry F F F    
             
Want            
ID Name Cond_1 Cond_2 Cond_3 Cond_4 Top
1 tom F       0
2 arthur F F F F 1
3 didier F F F F 0
4 françois F F F F 0
5 harry F F F   0

 

PaigeMiller
Diamond | Level 26

@WilliamB wrote:

Hello,

I would like to use macro variables, but I am not comfortable.

I have a number changing column cond_i from one time to another.

I would like a macro variable that counts the cond_i collones.

To allow to do

 

if cond_1 to cond_ & i = F then Top = 1 elce Top = 0

 

You need to use ARRAYs and not macros.

--
Paige Miller

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
  • 2 replies
  • 331 views
  • 0 likes
  • 3 in conversation