data have;
infile cards dlm='|';
input Column1- Column4;
cards;
0000 | 0000 | 0000 | 2084
2081 | 0000 | 0000 | 0000
0000 | 2082 | 2083 | 0000
;
proc sql;
select max(Column1),max(Column2),max(Column3),max(Column4)
into : c1,: c2,: c3,: c4
from have;
quit;
%put _user_ ;
There's always 4 variables, 3 rows, and 4 values?
What will you be doing with those macro variables later on?
And what will that below code do?
I ask because in 90% (if not 100%) of cases it is not necessary to create a list of macro variables, but instead the code can be created (or called) directly from the dataset.
data _null_;
set have;
retain counter 0;
array col {*} column:;
do i = 1 to dim(col);
if col{i} ne '0000'
then do;
counter +1;
call symputx(cats('mvar',counter),col{i});
end;
end;
run;
Mind that perpetuating a bad code structure by adding even more bad code to it is always a bad idea. Improving suboptimal code is a worthy investment into your own future.
data have;
infile cards dlm='|';
input Column1- Column4;
cards;
0000 | 0000 | 0000 | 2084
2081 | 0000 | 0000 | 0000
0000 | 2082 | 2083 | 0000
;
proc sql;
select max(Column1),max(Column2),max(Column3),max(Column4)
into : c1,: c2,: c3,: c4
from have;
quit;
%put _user_ ;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.