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

 

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