Date: Tue, 10 Feb 2004 23:03:06 -0800
Reply-To: kanthan <airaha_m@REDIFFMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: kanthan <airaha_m@REDIFFMAIL.COM>
Organization: http://groups.google.com
Subject: Re: dynamic macro-programming with call symput
Content-Type: text/plain; charset=ISO-8859-1
Hi:
I give a soln to your problem. Might be my understanding of your
problem wrong. Just check the code below.
data _pst_3;
attrib num_value length=$1
pst_value length=$4
pst_name length=$6;
infile cards;
input @1 num_value $1
@3 pst_value $4
@7 pst_name $6.;
datalines;
2 pst20
3 pst30
5 pst50
;
%let num_rec = 10;
%macro find_pst_value;
data _null_;
do i=1 to nobs;
set _pst_3 point=i nobs=nobs;
pst_value =round(100 * num_value /&num_rec, .01);
call symput (pst_name,put(pst_value, 8.1));
end;
stop;
run;
%mend;
%find_pst_value;
%put " &pst20 : &pst30 : &pst50 ";
U have values: " 20 : 30 : 50 ".
- U have misunderstood the macro compile time and run time processing.
And moreover, u cant name a macro variable starting with a numeric
value. In your case, u are trying to create macro variables such as
20pst, etc.
To check this, if u give '%put &20pst;', it will just print '&20pst'.
As soon as the macro processor sees that a non-char and non '_' value
starts after &, the value would be considered just as a string. It
wont give any warning like 'the macro variable reference is not
resolved'.
-Kanthan.
----------------------------------------------------------------------------
rune@fastlane.no (Rune Runnestoe) wrote in message news:<24410121.0402100605.2b78711e@posting.google.com>...
> Hi,
>
> I make a file of 3 records, where one column is made empty, and then I
> try to fill pst_value with calculated valus, and assign values to the
> macro variables in column pst_name:
>
> data &bibl.._pst_3;
> attrib num_value length=$1
> pst_value length=$4
> pst_name length=$6;
> infile cards;
> input @1 num_value $1
> @3 pst_value $4
> @7 pst_name $6.;
> datalines;
> 2 20pst
> 3 30pst
> 5 50pst
> ;
> run;
>
> %let num_rec = 10;
>
> %macro find_pst_value;
> data &bibl.._pst_4 (drop=i);
> %global count_pst_ib_1;
> %let count_pst_ib_1 = 0;
> set &bibl.._pst_3 end=no_more;
> if no_more then
> call symput('count_pst_ib_1', _n_);
> do i=1 to &count_pst_ib_1;
> pst_value =round(100 * num_value /&num_rec, .01);
> call symput (pst_name,put(pst_value, 8.1));
> end;
> run;
> %mend;
>
> %find_pst_value;
>
> %put &20pst;
>
>
> The column pst_value remains empty after this code. And the macro
> variable &20pst does not resolve to 20. How do I make it work the way
> I want ?
>
>
> Regards
> Rune Runnestoe