BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jeff_DOC
Pyrite | Level 9

Good morning. I'm hoping someone could help me with an error I'm receiving. 

 

I've simplified my steps as much as I can to attempt to pin down where my error is coming from but so far I've been unsuccessful.

 

In running the attached code I get the following error:

 

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, BTRIM, INPUT, PUT, SUBSTRING,
USER.

 

What I'm attempting to do is to initialize a variable and then use that variable in a SQL step. The first error I received was the SQL step looking for the "location_str" variable as a column in the SAS_COMM_TEST_DATA file. That was really strange since I am looking at the values within the location variable not the actual variable names. These steps seem pretty straight forward but I can't seem to determine where I've gone wrong with either error. I know there must be a better way to do this but this is what I have in an attempt to just get it to work.

 

I'd sure appreciate any help or advice on how to best/better proceed.

 

Thank you.

data _null_;
	if week_day = 2 then do;
		location_str = 'LOCA 1';
		title_location = 'LOCA 1';
	end;

	call symput("location_str",location_str);
	call symput("title_location",title_location);
run;

proc sql;
	create table test_01 as
	select a.key, a.location
	from SAS_COMM_TEST_DATA as a
	where a.location contains (&location_str.)
	order by a.key;
quit;
key location
1 LOCA 1
2 LOCA 2
3 LOCA 3
4 LOCA 4
5 LOCA 5
6 LOCA 6
7 LOCA 7
8 LOCA 8
9 LOCA 9
10 LOCA 10
11 LOCA 11
12 LOCA 12
13 LOCA 13
14 LOCA 14
15 LOCA 15
16 LOCA 16
17 LOCA 17
18 LOCA 18
19 LOCA 19
20 LOCA 20

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I am assuming that variable location is a character string, so you must compare it to a character string. Thus you need double-quotes around the macro variable to indicate that you have a character string.

 

Try this

where a.location contains ("&location_str")

From now on, please when there is an error in the log, show us the ENTIRE log for that PROC or DATA step. Do not show us errors disconnected from the code as it appears in the log.

--
Paige Miller

View solution in original post

3 REPLIES 3
Reeza
Super User
If you change CALL SYMPUT to CALL SYMPUTX() does that work?
PaigeMiller
Diamond | Level 26

I am assuming that variable location is a character string, so you must compare it to a character string. Thus you need double-quotes around the macro variable to indicate that you have a character string.

 

Try this

where a.location contains ("&location_str")

From now on, please when there is an error in the log, show us the ENTIRE log for that PROC or DATA step. Do not show us errors disconnected from the code as it appears in the log.

--
Paige Miller
Jeff_DOC
Pyrite | Level 9

Thank you very much.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 363 views
  • 2 likes
  • 3 in conversation