Unresolved Macro References

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 120
Accepted Solution

Unresolved Macro References

I am applying the following code to the attached .csv file; I am trying to assign each of the observations corresponding to dataset StepRateSchedules to macro variables and then have each of the macro variables displayed in my log (%put statements). For some reason, my macro references below do not get resolved.

Any ideas on why that may be the case and how I can accomplish my goal?


data WORK.StepRateSchedules;
     infile '/FilePath/RateSchedule.csv' dsd lrecl=40000 firstobs=3;
     informat Cusip $10.;
     informat AnnualCouponRateDates mmddyy10.;
     informat AnnualCouponRates 5.;
     format AnnualCouponRateDates yymmddn8.;
     input Cusip AnnualCouponRateDates AnnualCouponRates;
run;


%macro RateAssignment();

  %let dsid=%sysfunc(open(StepRateSchedules));
  %let Nobs=%sysfunc(attrn(&dsid,nlobs));
  %let dsid=%sysfunc(close(&dsid));

  %do i=1 %to &Nobs;
    proc sql;
      select AnnualCouponRates, AnnualCouponRateDates
      into :Rate&i, :RateDate&i
      from StepRateSchedules (obs=&i);
  %end;


%mend;

%RateAssignment();

%put &&Rate&i;

%put &&RateDate&i;

Attachment

Accepted Solutions
Solution
‎09-23-2014 11:47 AM
Grand Advisor
Posts: 17,342

Re: Unresolved Macro References

Those macro variables are created locally so disappear when the macro ends.

Don't use a macro for this though, SQL will create a list of variables for you. Choose an endpoint that will always be greater than the number of observations and SAS will only create the macro variables needed.

proc sql;
  select AnnualCouponRates, AnnualCouponRateDates
  into :Rate1-:Rate99999, :RateDate1-:RateDate99999
  from StepRateSchedules;

quit;

%put &rate1;

%put &rate99;

%put &rate1000;

View solution in original post


All Replies
Solution
‎09-23-2014 11:47 AM
Grand Advisor
Posts: 17,342

Re: Unresolved Macro References

Those macro variables are created locally so disappear when the macro ends.

Don't use a macro for this though, SQL will create a list of variables for you. Choose an endpoint that will always be greater than the number of observations and SAS will only create the macro variables needed.

proc sql;
  select AnnualCouponRates, AnnualCouponRateDates
  into :Rate1-:Rate99999, :RateDate1-:RateDate99999
  from StepRateSchedules;

quit;

%put &rate1;

%put &rate99;

%put &rate1000;

Frequent Contributor
Posts: 120

Re: Unresolved Macro References

Reeza,

Thanks, this is a very good suggestion; for some reason I tend to default to macros. One follow up question on the above, however.

I need to be able to list out ALL variables defined in my list (ie from &Rate1 to &&Rate&SQLOBS) and I won't necessarily know how many are in each list. Any simple suggestions?

Grand Advisor
Posts: 17,342

Re: Unresolved Macro References

You can still capture the &sqlobs and use that.

But why the need to list them out? If you have to display them then use the display from teh SQL table

or look at sashelp.vmacro table

Respected Advisor
Posts: 4,976

Re: Unresolved Macro References

The quick and dirty way is easy to program:

%put _user_;

However, it may give you a little more information than you are looking for, and in a different order than you are hoping for.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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