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

proc sql;

select count(*) into :cntr from NVPLocal.NVP_DOD_Catch ;

%put &cntr;

select distinct qrm_db,strategy,moddate into :Var1,:Var2,:Var3 from NVPLocal.NVP_DOD_Catch ;

%put &Var1;

%put &Var2;

%put &Var3;

run;

proc sql outobs=10;

connect to odbc (DSN=&DSN user=&user password=&pwds);

create table temp as select * from connection to odbc (

select * from [FASTControl].[dbo].[ALM_NVPData]

where qrm_db=&Var1

);

disconnect from odbc;

getting error message

ERROR: CLI describe error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'Jan21'. : [Microsoft][SQL

Server Native Client 11.0][SQL Server]Statement(s) could not be prepared.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If sounds like there is no variable named Jan21.  Did you want use the value of VAR1 macro variable as a string literal?

If so why not just add the quotes when generating the macro variable. So if you did this:

select quote(trim(qrm_db),"'") into :Var1 from NVPLocal.NVP_DOD_Catch ;

Then VAR1 will contain 'Jan21' instead of just Jan21.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

First, write the code so that you can get it to work WITHOUT macro variables. Then, it should be relatively easy to get the code to work WITH macro variables. Show us that code that works without macro variables.

 

Also, when you get ERRORs, show us the LOG, the entire log for these two PROC SQLs, with nothing chopped out, in the order that it appears in the log. 

--
Paige Miller
Tom
Super User Tom
Super User

If sounds like there is no variable named Jan21.  Did you want use the value of VAR1 macro variable as a string literal?

If so why not just add the quotes when generating the macro variable. So if you did this:

select quote(trim(qrm_db),"'") into :Var1 from NVPLocal.NVP_DOD_Catch ;

Then VAR1 will contain 'Jan21' instead of just Jan21.

Ashpak
Calcite | Level 5
Thanks this got worked out.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 424 views
  • 0 likes
  • 3 in conversation