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

I am working with SAS Viya. 

Here is my code

cas;
caslib _all_ Assign;

proc fedsql sessref=casauto;
create table PN_Transit as
(select distinct Port1 from LM.TRANS
where MasterClientName = 'D'
and datepart(EffectiveDate) ='01MAY2019');
quit;

 

LM.TRANS is a table in SQL that is connected. This query works just fine if I do not have the date filter. It works for any other filter that I want to have except the date one. So I am not sure if this is the right syntax. This does create a table called PN_Transit like I wanted it to but i returns 0 observations. I tried several combinations in the date filter but in vain. In the SQL table, the effective date is actually stored as "2019-05-01 00:00:00.000". How do I get this working?

1 ACCEPTED SOLUTION
13 REPLIES 13
Santha
Pyrite | Level 9

I got it by doing and put(datepart(Effectivedate), date9.)='01MAY2019')

Worked just fine.

Reeza
Super User
datepart(effectiveDate) = '01May2019'd

The above should work as well.

 


@Santha wrote:

I got it by doing and put(datepart(Effectivedate), date9.)='01MAY2019')

Worked just fine.


 

ChrisNZ
Tourmaline | Level 20

Not using a function would speed up your query. Like this:

 

where effectiveDate = "01may2019:00:00:00"dt

 

ChrisNZ
Tourmaline | Level 20

You need to tell SAS this is a date. Add D after the string:

 

datepart(EffectiveDate) = '01MAY2019'd

 

Other letters can be added like T for time, DT for datetime, X for hexadecimal, N for name, B for binary.

Santha
Pyrite | Level 9

I tried adding "d" after the string. It does not like it. It says "syntax error" near "D"

Reeza
Super User
With your date in that format? Can you post the code/log?
Santha
Pyrite | Level 9
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
75
76 proc fedsql sessref=casauto;
77 create table PN_Transit as
78 (select distinct Port1 from LM.TRANS
79 where MasterClientName = 'D'
80 and datepart(EffectiveDate) ='01MAY2019'd);
ERROR: Syntax error at or near "D"
ERROR: The action stopped due to errors.
ERROR: The FedSQL action was not successful.
NOTE: PROC FEDSQL has set option NOEXEC and will continue to prepare statements.
81 quit;
NOTE: PROCEDURE FEDSQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
82
83 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
ChrisNZ
Tourmaline | Level 20

Still compare to a datetime though, rather than converting to a date.

PaalNavestad
Pyrite | Level 9

Why is this so well hidden? Really hard for current SAS programmers when there is a syntax change like this.

Reeza
Super User
How is something that has it's own chapter in the documentation "hidden"?

FEDSQL is essentially another language entirely, like HASH table coding for example.
PaalNavestad
Pyrite | Level 9

Hidden is mainly the wrong word. The challenge is that it is rather different from the SQL procedure so an article, or change type log would have been good.

PaalNavestad
Pyrite | Level 9
Hi the documentation explain the way dates and time is handled. I had a challenge understanding this.
The way to use a date in a where clause is

where dateVariable >= date'2015-01-01'
a bit confusing as you tell what it is in front and that there are no () before the date constant.
Fortunatly the date() function worked well in subsets.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 13 replies
  • 4043 views
  • 7 likes
  • 4 in conversation