Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro questions? 1

Status
Not open for further replies.

nobyrnes

Programmer
Mar 20, 2007
15
IE
Why cant I use proc format in a macro I call. I keep getting errors with this?
%macro R061_Key_Summary_output_Subseg(Datain=, Dataout=, Seg=, Subseg=, Provider=&ProviderText, ReportDateText=,);

Data &Datain;
Set &Datain;
PROC FORMAT;
VALUE picture p8r
low - < 5 = '0009.99%'
5 - high = '0009%';

;
%mend R061_Key_Summary_output_Subseg



Also I want to create a col in a dataset using a macro.
eg
&Seg=5
This works fine, but I cannot force &Seg to be a number format. I do all the usual stuff, format &seg 1.;

And last one:
I want to use macro vars in put statements for a dde link to excel. eg:
PUT '[open("c:\SASDatafile\TMPoutput.xls")]';

but I want something like
PUT "'[open("c:\SASDatafile\&output.xls")]'";
but it always justs pasts the above statement into a cell, instead of running the put statement.

Any help appreciated, its been a long day.
N


 
Change: PUT "'[open("c:\SASDatafile\&output.xls")]'";
To: PUT '[open("c:\SASDatafile\&output..xls")]';

I thing now will be OK.
 
That still will not work. Remember that macro vars do not resolve inside single quotes.
Your code
Code:
 PUT '[open("c:\SASDatafile\&output..xls")]';

This is how it should look
Code:
 PUT '[open("' "c:\SASDatafile\&output..xls" '")]';

Notice that the middle part of the PUT statement is in double quotes. This will allow the macro compiler to resolve the macro variable.

To create a varibale in a dataset via macro, you should use the macro variable in a length statement.
ex.
%let newvar = name;

data test;
length &newvar 8
;
run;

&newvar will resolve to the variable name of your choice. The '8' tells SAS that the preceeding variable is a numeric variable.


To you first question, you can't mix proc steps and data steps. So your proc step stops your datastep and never does what you wanted it to do. If you want some help in how to accomplish what you need done, post a little more of your problem.

Klaz
 
Hi nobyrnes,

You Macro should be written as

Code:
%macro R061_Key_Summary_output_Subseg(Datain=, Dataout=, Seg=, Subseg=, Provider=&ProviderText, ReportDateText=);

Data &Datain;
     Set &Datain;
PROC FORMAT;
    VALUE picture p8r
        low - < 5 = '0009.99%'
        5 - high = '0009%';

;
run;
%mend R061_Key_Summary_output_Subseg;

No Comma after "ReportDateText" macro parameter.

Your PROC FORMAT segment doesn't have a RUN statement. Thus, the entire step never is complete, thus causing your error. As for the DATA step, the PROC keyword would act as the step boundary.

Sarav
 
Reg. the previous code, remove the extra semicolon in the PROC FORMAT statement (before the RUN statement).

Sarav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top