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

Good morning,

 

I found a script on our server and I am not sure how to interpret it.

 

Here's a simplify version of the code.  So we are trying to create a table named mytable from the contains of table10 which contains few variables , including the variable from and to.  The variable from to contains date like 20081231 to 99991231.

 

So suppose that we have %let dateproduction='20200131'

 

I believe the le statement means less or equal but how will work the where statement?

 

Thanks for your help

 

 

 

proc sql;
create table mytable as
select *
from table10
where( calculated from le "&DATEPRODUCTION." le calculated to
);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are FROM and TO character strings like '20081231' or numbers like 20,081,231?

If they are strings then generated SAS code in the WHERE clause needs to contain with single or double quotes, but your example code is going generate both double and single quotes.  It they are numbers then you do not want any quotes.

 

The LE operator means less than or equal to, which you also write as <= .

 

You do not need the CALCULATED keyword in this example if FROM is a variable that is coming from the input TABLE10.  If FROM was the name of some generated variable listed in the SELECT statement then you would need the CALCULATED keyword.

 

If FROM and TO are character you could keep the quotes in the macro variable:

%let dateproduction='20200131';
proc sql;
create table mytable as
  select *
  from table10
  where  (from le &DATEPRODUCTION. le to)
;
quit;

Or not put the quotes in the macro variable and instead add them back into the generated code.

%let dateproduction=20200131;
proc sql;
create table mytable as
  select *
  from table10
  where  (from le "&DATEPRODUCTION." le to)
;
quit;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Do you mean you want to extract all records where &dateproduction is greater than or equal to variable FROM and less than or equal to variable TO?

--
Paige Miller
Tom
Super User Tom
Super User

Are FROM and TO character strings like '20081231' or numbers like 20,081,231?

If they are strings then generated SAS code in the WHERE clause needs to contain with single or double quotes, but your example code is going generate both double and single quotes.  It they are numbers then you do not want any quotes.

 

The LE operator means less than or equal to, which you also write as <= .

 

You do not need the CALCULATED keyword in this example if FROM is a variable that is coming from the input TABLE10.  If FROM was the name of some generated variable listed in the SELECT statement then you would need the CALCULATED keyword.

 

If FROM and TO are character you could keep the quotes in the macro variable:

%let dateproduction='20200131';
proc sql;
create table mytable as
  select *
  from table10
  where  (from le &DATEPRODUCTION. le to)
;
quit;

Or not put the quotes in the macro variable and instead add them back into the generated code.

%let dateproduction=20200131;
proc sql;
create table mytable as
  select *
  from table10
  where  (from le "&DATEPRODUCTION." le to)
;
quit;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 638 views
  • 0 likes
  • 3 in conversation