Macro variables are resolving but not able to get the corresponding data

Reply
Frequent Contributor
Posts: 110

Macro variables are resolving but not able to get the corresponding data

Hi SAS Experts,

 

Am trying to create two macro variables one for Year  one for Product in sashelp.prdsal2 dataset.

When am substituting both the macro variable, the variables are resolving but the am unable to get the corresponding data.

Below is my code... Please guide me about my mistake


%LET YR=1995;
%LET PD='SOFA';

PROC SQL;
CREATE TABLE NEW AS
SELECT DISTINCT PRODUCT,SUM(ACTUAL) AS TOTAL,STATE FROM SASHELP.PRDSAL2
WHERE YEAR=&YR. AND PRODUCT="&PD"
GROUP BY STATE;
QUIT;

/*By using the above code am not getting any data and there is no error*/

 

PROC SQL;
CREATE TABLE NEW1 AS
SELECT DISTINCT PRODUCT,SUM(ACTUAL) AS TOTAL,STATE FROM SASHELP.PRDSAL2
WHERE YEAR=1995. AND PRODUCT="SOFA"
GROUP BY STATE;
QUIT;

/*without using the macro variable am getting the information*/

Grand Advisor
Posts: 17,427

Re: Macro variables are resolving but not able to get the corresponding data

Too many quotation marks

 

it will resolve to, extra spaces added for illustration. 

 

product = " ' Sofa ' " ; 

 

Remove the single quotes from your macro variable declaration. 

Frequent Contributor
Posts: 110

Re: Macro variables are resolving but not able to get the corresponding data

Hi,

As you suggested I have removed the qoutes but still it is not working..

 

If it is possible could you please right the code with change. please guide

Grand Advisor
Posts: 17,427

Re: Macro variables are resolving but not able to get the corresponding data

Post your new code. 

You should only have removed the quotes from the LET statement. 

 

Basically you need to make the macro code generate text that's valid SAS syntax. 

Esteemed Advisor
Posts: 5,199

Re: Macro variables are resolving but not able to get the corresponding data

You have single quotes around SOFA in the macro variable. Since you are using double quotes in the SQL, the single quotes will be a part of the string matching criteria.

Either omit the single or the double quotes.

options symbolgen;

can help you notice such mistakes.

Data never sleeps
Super User
Posts: 1,244

Re: Macro variables are resolving but not able to get the corresponding data

remove the dot after the year 1995 (you wrote: 1995.)

 

the dot after a macro varible assigns its end

Ask a Question
Discussion stats
  • 5 replies
  • 310 views
  • 0 likes
  • 4 in conversation