BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

what does

put(fdate+1,date9.) mean?

what does it mean to add 1 here?

say fdate is 31Aug2021

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

A SAS Date is an integer. So adding 1 will give you the next day.

 

The put statement converts the numeric SAS variable into character.

mkeintz
PROC Star

Assuming fdate is a date value (i.e. number of days since 01jan1960), then to represent 31aug2021, the underlying value of date is 22523.  That can be revealed by running this code:

 

data _null_;
   fdate='31aug2021'd;
   put fdate=;
   put fdate=date9. ;
run;

which generates this log:

6761  data _null_;
6762    fdate='31aug2021'd;
6763    put fdate=;
6764    put fdate=date9.;
6765  run;

fdate=22523
fdate=31AUG2021
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

But you ask about the put function (unlike the put statements above).  AS @PeterClemmensen says, it calculates the first argument (i.e. adding 1 to the value 22523, getting 22524), and converts it to a character string using the date9. format, yielding the character "01sep2021":

 

data _null_;
  fdate='31aug2021'd;
  z=put(fdate+1,date9.);
  put z=;
run;

Run these programs and take a look at the log.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
AMSAS
SAS Super FREQ

Here's the documentation links with good examples

 

PUT Function 

Working with Dates in the SAS System

 

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2002 views
  • 0 likes
  • 4 in conversation