BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

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*/

5 REPLIES 5
Reeza
Super User

Too many quotation marks

 

it will resolve to, extra spaces added for illustration. 

 

product = " ' Sofa ' " ; 

 

Remove the single quotes from your macro variable declaration. 

sanjay1
Obsidian | Level 7

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

Reeza
Super User

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. 

LinusH
Tourmaline | Level 20

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
Shmuel
Garnet | Level 18

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

 

the dot after a macro varible assigns its end

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 770 views
  • 0 likes
  • 4 in conversation