Hi all,
I've written the macro below to run 217 regressions by the variable "code", and save the estimates for each one in a different dataset, and then I want to save the value of the variable "code" itself" in the output dataset generated through the data statement. The problem is the "code" (which is 3 characters) is being included perfectly fine for all but 5 of the 217 datasets, and I can't figure out why. Any thoughts?
%macro ln_gdp(code=);
proc glm data = two plots = none ;
model ln_gdp = year;
where code = "&code.";
ods output ParameterEstimates=PE_&code.;
run;
quit;
data PE_&code.; set PE_&code.;
code = "&code.";
run;
%mend ln_gdp;
****Executing the macro*****;
*Get list of all codes;
proc sql;
create table all_countries as
select distinct code
from two;
quit;
*Run macro;
data _null_; *macro_call;
set all_countries;*
*Build macro call string;
str = catt('%ln_gdp(code = ', code, ');');
*Call macro;
call execute(str);
run;
@aowais wrote:
The problem is the "code" (which is 3 characters) is being included perfectly fine for all but 5 of the 217 datasets, and I can't figure out why. Any thoughts?
What happens in those 5 datasets? Show us.
It drops the last character: e.g. for code = RWA, it only saves RW, for code = SWE = it only saves SW
@aowais wrote:
It drops the last character: e.g. for code = RWA, it only saves RW, for code = SWE = it only saves SW
Since we don't have your data, we can't reproduce this or debug it. Please show us the code from the LOG (using options mprint;) and show us the resulting data set for one example where this happens, or better yet, pay attention to @data_null__ and follow his suggestion and get rid of the looping.
Why don't you use BY CODE; instead of the WHERE and LOOP?
Even if you insist on using WHERE/loop you can still use BY CODE: and you DON'T have to create it later.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.