BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bman
Calcite | Level 5

Looking for a solution to an isue when I use Macro variables in a proc sql statement.  Here's what I'm doing.

The dataset(dailyRun) I'm working with has a field called ScID. This is character field with a length of 10

The code;

Prompt manager has a prompt called mySCID that will be filled in by the user when they run the code.

code to create a table

proc sql;

create table test as

select ScID from dailyRun

where ScID=&mySCID;

quit;

I get the following error "expression using equals(=)  has components that are different data types"

The &mySCID variable has 00100200 as the value.  If  I change the code and place the value '00100200' it works.

proc sql;

create table test as

select ScID from dailyRun

where ScID='00100200';

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

Hi,

try this:

proc sql;

create table test as

select ScID from dailyRun

where ScID="&mySCID";

quit;

Linlin

View solution in original post

6 REPLIES 6
Linlin
Lapis Lazuli | Level 10

Hi,

try this:

proc sql;

create table test as

select ScID from dailyRun

where ScID="&mySCID";

quit;

Linlin

bman
Calcite | Level 5

thanks that worked.  What does the double quotes do when SAS reads it. Does it convert the macro variable?

Linlin
Lapis Lazuli | Level 10

When comparing character variable with a value, we have to add “ “ to the value.

It is the same as “if sex="F";” in the code below:

data want;

set sashelp.class;

if sex="F" ;

run;

bman
Calcite | Level 5

Thanks. How would it work for a date prompt. I know when I have to do  a date value i place '01Apr2011',d when the field I'm checking against is a date field.  If I use a prompt for that and the user places 01apr2011 or 04012011 would I just put that variable in "" too?  I really appreciate your help. I'm new to SAS coding.

Linlin
Lapis Lazuli | Level 10

yes, you have to put the macro variable in " ".  example:

%let dt=01apr2011;

data have;

format date mmddyy10.;

input date mmddyy8.;

cards;

03012011

04012011

;

data want;

set have;

if date="&dt"d;

run;

proc print;run;

Linlin

bman
Calcite | Level 5

Thank you. I really appreciate the help.

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
  • 6 replies
  • 1858 views
  • 0 likes
  • 2 in conversation