I'm trying to create the binary format binary3. by concatenating the values 'binary', n, and '.', where n=3 is a value that will be read in from the data step (or possibly a macro variable).
So far the following code doesn't work - it should output a list of binary values for the integers 1 through 8 in the log file. Any ideas what's wrong with my format statement?
data _null_;
n = 3;
rows = 2**n;
/** construct one row at a time **/
format = cats('binary', char(n,1), '.');
do i = 1 to rows;
put @1 i format;
/* put @1 i binary3.;*/
end;
run;
Only the putc/putn function allow dynamic formats.
You could move the format-name to a macro-variable:
%let n = 3;
%let binaryformat = binary&n..;
data _null_;
rows = 2**&n.;
do i = 1 to rows;
put i &binaryformat.;
/* put @1 i binary3.;*/
end;
run;
data _null_;
n = 3;
rows = 2**n;
/** construct one row at a time **/
format = cats('binary', n, '.');
do i = 1 to rows;
b = putn(i, format);
put @1 i b;
end;
run;
B.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.