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

Reeza,

I would like to be able put a -1 or so where I can check a date less than today:

%if &date_to = %sysfunc(today()) %then %do;
Reeza
Super User
%if &date_to = %eval(%sysfunc(today()) - 1) %then %do;

Wrap it in %EVAL() to tell SAS to evaluate the value. You can also use INTNX() but in this case subtracting one is easy enough.

 


@Ivc wrote:

Reeza,

I would like to be able put a -1 or so where I can check a date less than today:

%if &date_to = %sysfunc(today()) %then %do;

 

Tom
Super User Tom
Super User

@Ivc wrote:

Reeza,

I would like to be able put a -1 or so where I can check a date less than today:

%if &date_to = %sysfunc(today()) %then %do;

What type of value did you put into the macro variable DATE_TO?  If it is an integer value then the implied %EVAL() that %IF will use to evaluate the condition will work.  But if DATE_TO has a date literal, like '01AUG2019'd then you will need to use %SYSEVALF() to make the comparison.

%let date_to="28JUL2019"d ;

%if %sysevalf(&date_to = (%sysfunc(today())-1) ) %then %do;
Ivc
Calcite | Level 5 Ivc
Calcite | Level 5

Tom,

The date is in this format:"20190726"

Tom
Super User Tom
Super User

@Ivc wrote:

Tom,

The date is in this format:"20190726"


That is NOT a date.  That is either an 8 character string that starts with the digit 2 or the number 20,190,726, depending on exactly how you have it.

 

If you want to convert it to a date then use the INPUT() , or INPUTN(), function with the YYMMDD informat.

Ivc
Calcite | Level 5 Ivc
Calcite | Level 5

Tom,

It is a string of 8 characters that signify the date for our purposes(the source system provides it in this format and it has to be exported the same way). I ran your code against the input file and the outcome seems to what I was expecting.

Tom
Super User Tom
Super User
It only makes a difference if you want to try to do things like your request to subtract one. Subtracting one from a string like '20190801' is impossible. Subtracting one from a number like 20190801 will yield 20190800 and not 20190731. So if you want to work with them as actual dates you will need to convert them to date values. You can then display them using any date format you want, including YYMMDDN8., which will make strings that look like your example.
Reeza
Super User

If you're using the code I wrote, it's not. It should be an integer value but not in the format you've shown. Did you check the macro variables values or just the variable value?

 


@Ivc wrote:

Tom,

The date is in this format:"20190726"


 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

there should be a pattern to the file being updated.  Is the task that needs to be ran monthly, daily, hourly?  Please be kind to the network interruptions you impose on your companions?  It sounds like a job scheduler task to me.

Tom
Super User Tom
Super User

That is one ugly data step. Looks like it was generated by PROC IMPORT.

 

You can use the optional CANCEL option on the RUN statement prevent the data step from running.  That way you can control wheter it runs without having to learn how to generate code conditionally. 

 

Just read enough of the file to check it you want to really read it or not and set a macro variable. Might be best to make the default be to NOT run the step and only run it when the file pases the test.  Then an empty file will not try to be read.

 

filename ameritot '\\nyadpam\nyadpam_d\apps\CWA_Bondedge_INTMUTUALAMERI_TOT\Bondedge_upload_INTMUTUALAMERITOT.csv';

%let run_cancel=CANCEL ;
data _null_;
  infile ameritot firstobs=2 obs=3 dsd ;
  input date_to :$10. ;
  if input(date_to,??anydtdte.) = today() then call symputx('run_cancel',' ');
run;

data bondedge_upload_tot;
  infile ameritot dsd truncover firstobs=2 ;
  length Date_To $10 CUSIP $14 Market_Price $10 Portfolio $21
         Orig_Face $17 Actual_Par $18 Book_Price $10 Security_Type_Description $14
  ;
  input Date_To -- Security_Type_Description;
run &run_cancel ;

 

Reeza
Super User
The CANCEL option is a nifty little trick, still learning new things 🙂
Ivc
Calcite | Level 5 Ivc
Calcite | Level 5

Tom,

I now tested your codes and it seems to be providing the results I am expecting. I will now try to understand the coding.  Thanks.

Ivc
Calcite | Level 5 Ivc
Calcite | Level 5

Tom,

What function does '--' do in this line:?

input Date_To -- Security_Type_Description;

Tom
Super User Tom
Super User
That is a position based variable list. A variable list is a shortcut way of writing a list of variable names. The double hyphen means take all of the variable defined between (and including) the two listed based on the order that the variables are defined in the dataset. So it is important to make sure that the variables are defined in the data step in the order that they appear in the text file.
You can use a colon to match names that start with a given prefix. Like VAR:
You can use just a single hyphen when the names of the variables in the list end in a numeric suffix. Like VAR1-VAR20. Unlike the other two this one does not require that the variables have already been defined, since it does not need any more information to figure out what names the shortcut represents.
Ivc
Calcite | Level 5 Ivc
Calcite | Level 5

Tom,

Thanks for the education on the hyphen.

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
  • 29 replies
  • 1429 views
  • 6 likes
  • 6 in conversation