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 |
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
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
@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.
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!
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.