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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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