I want to make a string variable with a number of 0's (say 842 for example).
This works:
I worry about the space for a variable of length 842 (should I?), so I decide to split the variable into parts that are length 100. So if I want 842 zeroes, then I decide I should make 9 variables
part0 = 000...000 (100 zeroes)
part1 = 000...000 (100 zeroes)
part2 = 000...000 (100 zeroes)
etc
part8 = 000...000 (42 zeroes)
On the other hand, if I want a variable with 2097 zeroes, then I will need 21 variables. Thus, the problem I'm facing is that I need to be flexible in the variables part# that I create. I figure one way to go about this is using a macro variable &n1 and letting it run from 0 to {number of variables-1}, but I don't know how to assign &n1--I tried using call symput() but am having trouble.
I tried this:
I get this warning
WARNING: Apparent symbolic reference N1 not resolved.
Flummoxed because if I put %put _user_; inside the macro, and drop the %zerofill statements, then I see that &n1 is getting assigned. But when I try to reference part&n1 something is wrong.
I have two requests that I think can be answered:
1) What can I do to fix my code? There must be some way to do this, using %NRSTR or something like that?
and/or 2) Do you have another suggestion to do what I want?
I can get by for now by just setting my limit to 100 parts, but I'd like to know what's going wrong.
This works:
Code:
*Macro to make a string var of specified length;
%macro zerofill(strname, strlength);
length &strname $100.;
%let strtemp=%eval(&strlength);
%do %while (&strtemp>0);
substr(&strname, &strtemp, 1)="0";
%let strtemp=%eval(&strtemp-1);
%end;
%mend zerofill;
part0 = 000...000 (100 zeroes)
part1 = 000...000 (100 zeroes)
part2 = 000...000 (100 zeroes)
etc
part8 = 000...000 (42 zeroes)
On the other hand, if I want a variable with 2097 zeroes, then I will need 21 variables. Thus, the problem I'm facing is that I need to be flexible in the variables part# that I create. I figure one way to go about this is using a macro variable &n1 and letting it run from 0 to {number of variables-1}, but I don't know how to assign &n1--I tried using call symput() but am having trouble.
I tried this:
Code:
%macro wrong(bignumber);
data init;
_init=%eval(&bignumber);
_init_head=int(_init/100);
_init_tail=mod(_init,100);
_i=0;
do while (_i < _init_head);
call symput("n1", compress(_i));
%zerofill(part&n1,100);
_i = _i + 1;
end;
call symput("n1", compress(_init_head));
%zerofill(part&n1,_init_tail);
run;
%mend;
WARNING: Apparent symbolic reference N1 not resolved.
Flummoxed because if I put %put _user_; inside the macro, and drop the %zerofill statements, then I see that &n1 is getting assigned. But when I try to reference part&n1 something is wrong.
I have two requests that I think can be answered:
1) What can I do to fix my code? There must be some way to do this, using %NRSTR or something like that?
and/or 2) Do you have another suggestion to do what I want?
I can get by for now by just setting my limit to 100 parts, but I'd like to know what's going wrong.