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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.