Hi Team,
I want to do a "do loops" 3 times with 75 obervations
With my example I am getting from 00 to 24 with 25 observations
Do you know how to do it?
Thanks
data test;
%do i1=0 %to 24 ;
%let i = %sysfunc(putn(&i1,z2.));
%end;
I just copied and hadn't tested your code. Try the following:
data test (keep=i); do ii=1 to 100; do jj=1 to 25; i = put(jj,z2.); output; end; end; run;
Art, CEO, AnalystFinder.com
You're doing nothing besides creating (local) macro variable i1 with value 25 and (local) macro variable i with value 24.
Since this is obviously only part of your code, as it would not work on its own (%macro and %mend missing), please post your whole code, the log and the expected result.
What are you trying to do? Your example doesn't produce any records and won't run as it incorporates macro code outside of a macro. If you're trying to create records, you'll have to create and set the value of a variable rather than an a macro variable.
You can always nest loops. e.g.
data test; do ii=1 to 3; do jj=0 to 24 ; i = %sysfunc(putn(jj,z2.)); output; end; end; run;
Art, CEO, AnalystFinder.com
this is the output that I need:
01 |
02 |
03 |
04 |
05 |
06 |
07 |
08 |
09 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
01 |
02 |
03 |
04 |
05 |
06 |
07 |
08 |
09 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
01 |
02 |
03 |
04 |
05 |
06 |
07 |
08 |
09 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
Then just use something like:
data test (keep=i);; do ii=1 to 3; do jj=1 to 25 ; i = putn(jj,z2.); output; end; end; run;
Art, CEO, AnalystFinder.com
This worked properly:
data test (keep=jj);;
do ii=1 to 100;
do jj=1 to 25 ;
output;
end;
end;
run;
Why this does not work??
data test (keep=jj);;
do ii=1 to 100;
do jj=1 to 25 ;
i = %sysfunc(putn(jj,z2.));
output;
end;
end;
run;
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.
43 i = %sysfunc(putn(jj,z2.));
_
22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
@Jcorti wrote:
Why this does not work??
data test (keep=jj);; do ii=1 to 100; do jj=1 to 25 ; i = %sysfunc(putn(jj,z2.)); output; end; end; run;
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number. ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated. 43 i = %sysfunc(putn(jj,z2.)); _ 22 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT.
%sysfunc is a macro function that is resolved by the macro processor before the data step is compiled, so it never has access to data step variable values, only names. The way it's written here, it then tries to run the data step function as
putn("jj",z2.)
Since putn expects a numeric value as its first argument -> boom.
The %sysfunc wrapper was a remnant from your earlier code and should have been removed.
You have one loop that creates 0 to 24 - you've explicitly put that in your code, if you want 1 to 25 change the values in your %DO/%TO statement.
If you want it repeated 3 more times, wrap it another loop that goes through three times.
It doesn't make sense with macro variables though becaue the values will get overwritten.
Art's code shows the structure you need whether you're using macro's or a data step.
You also don't specify what output type you need, a dataset, log output or a displayed report ie in HTML or PDF.
You don't need the %SYSFUNC in Art's code so I removed that.
3 times is only an example that I need, actually I need 100 times repetead the same loop in order to create the table required with one column like shown above.
I need that table because I will concatenate with another table.
So, can we presume that you now have what you needed?
Art, CEO, AnalystFinder.com
I just copied and hadn't tested your code. Try the following:
data test (keep=i); do ii=1 to 100; do jj=1 to 25; i = put(jj,z2.); output; end; end; run;
Art, CEO, AnalystFinder.com
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.