BookmarkSubscribeRSS Feed
aowais
Obsidian | Level 7

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;

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
aowais
Obsidian | Level 7

It drops the last character: e.g. for code = RWA, it only saves RW, for code = SWE = it only saves SW

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
data_null__
Jade | Level 19

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.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 886 views
  • 1 like
  • 3 in conversation