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*/
Too many quotation marks
it will resolve to, extra spaces added for illustration.
product = " ' Sofa ' " ;
Remove the single quotes from your macro variable declaration.
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
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.
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.
remove the dot after the year 1995 (you wrote: 1995.)
the dot after a macro varible assigns its end
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.