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


I have a SAS data set with two variables:  load_dt, a date value formatted as mmddyy10, and n_recs_sas, a numeric value.

I want to use PROC SQL to insert a new record.  load_dt must have the current date.  I'm loading n_recs_sas from a macro variable.

The query is not letting me use the today() or date() function in the VALUES clause.  The error message is explicit, but can anyone tell me why?  I know there are a couple work arounds but I'd like to understand what's going on here.

 

714 proc sql;

715 insert into test2

716 (load_dt, n_recs_sas)

717 values (

718 today() as load_dt format=mmddyy10.

-----

22

76

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,

a missing value, +, -, MISSING, NULL, USER.

ERROR 76-322: Syntax error, statement will be ignored.

719 , input(put("&_numRecsInFinalDSN",$8.),8.)

720 );

721 quit;

NOTE: The SAS System stopped processing this step because of errors.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

VALUES wants constants, not functions or queries. You can use %SYSFUNC() to call TODAY() function and have result appear as if you typed it.  The same actually applies to your macro variable.  So your statement becomes:

  insert into test2 (load_dt , n_recs_sas)

  values (%sysfunc(today()),&_numRecsInFinalDSN)

  ;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

VALUES wants constants, not functions or queries. You can use %SYSFUNC() to call TODAY() function and have result appear as if you typed it.  The same actually applies to your macro variable.  So your statement becomes:

  insert into test2 (load_dt , n_recs_sas)

  values (%sysfunc(today()),&_numRecsInFinalDSN)

  ;

KarlK
Fluorite | Level 6

Another alternative is to use the "set" syntax of the insert statement:

proc sql;

insert into test2 set load_dt = today();

quit;

In addition, I don't think there are any circumstances in which the insert statement allows "as" or "format=" as you have in your OP.

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