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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 420 views
  • 0 likes
  • 3 in conversation