Help using Base SAS procedures

Quote Macro Input Data Set

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Quote Macro Input Data Set

I want to check if there's a certain variable named "ABC"  in the input data set. I can realize it using the following data step:

data want;

set have;

dsid=open('have');

check=varnum(dsid,'ABC');

run;

I will check 'check' and use it for further programming. Now I want to realize the same function using a macro. I have tried the following but it didn't work.

%macro test(&input);

data want;

set &input;

dsid=open('&input');                       *The problem might be here;

check=varnum(dsid,'ABC');

run;

%mend;

%test(xxxx)

Does anyone offer some help? Thank you so much!


Accepted Solutions
Solution
‎05-28-2013 07:47 PM
Super User
Posts: 19,768

Re: Quote Macro Input Data Set

Posted in reply to PeterPanPan

macro variables only result inside double quotes, not single quotes.

Change to double quotes.

You may also want to consider looking at capturing the outputs of proc contents or querying the dictionary table instead. These are especially useful when your data is large.

View solution in original post


All Replies
Solution
‎05-28-2013 07:47 PM
Super User
Posts: 19,768

Re: Quote Macro Input Data Set

Posted in reply to PeterPanPan

macro variables only result inside double quotes, not single quotes.

Change to double quotes.

You may also want to consider looking at capturing the outputs of proc contents or querying the dictionary table instead. These are especially useful when your data is large.

Occasional Contributor
Posts: 7

Re: Quote Macro Input Data Set

Thank youSmiley HappySmiley HappySmiley Happy

Super User
Posts: 3,250

Re: Quote Macro Input Data Set

Posted in reply to PeterPanPan

Use double quotes so your &input will resolve: "&input"

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 123 views
  • 3 likes
  • 3 in conversation