SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tianerhu
Pyrite | Level 9

tianerhu_0-1615240155141.png

What does the upperletter D mean  ? and why is the code wrong? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

With pictures it is hard to tell but it appears to me that there is a space between the " and the D

Examine the lines below:

"01JAN1960" D
"01JAN1960"D

The first would be an error, the second is a date literal. Date literal is the way that you tell SAS you want to use the internal numeric representation of a date (or datetime or time value). The D could be lower case as could the month abbreviation. But there cannot be a space between the quote and the letter.

Example log from running code involving those two lines:

58   data junk;
59      x="01JAN1960" D;
                      -
                      22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,
              =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |,
              ||, ~=.

60   run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      59:6
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.JUNK may be incomplete.  When this step was stopped there were 0
         observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


61
62   data junk2;
63      x="01JAN1960"D;
64   run;

NOTE: The data set WORK.JUNK2 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

The underscore under the letter D in the first bit is "unexpected" because of the space.

 

Pictures of proportional font text can be hard to tell but I think that is the issue in this case.

If you copy and run my code you will find the value of X in the Junk2 data set is indeed 0. 1 January 1960 is the base numeric value for dates and is day "zero".

 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

The D indicates that SAS will convert the value inside the double-quotes to a valid SAS date. SAS dates are integers, representing the number of days since 01JAN1960, so the correct value is 0 (if there are no syntax errors). Had the code read

 

x="01JAN2020"d;

the value would be 21915, the number of days since 01JAN1960.

--
Paige Miller
tianerhu
Pyrite | Level 9
Thank you.
Reeza
Super User

It's a "constant" (could have sworn it was once called literal) and tells SAS to interpret the data in quotes as a date. 

 

Some of the other options you may see:

 

DT -> Datetime

T -> Time

N -> Variable or data set name

 

This also means if you add code right after the end of the quotation marks you can sometimes get a message about the behaviour of a variable after a quote changing over time. 

 

Characters That Follow a Character Constant

   Possible Interpretations

    Examples

b

bit testing constant

'00100000'b

d

date constant

'01jan04'd

dt

datetime constant

'18jan2005:9:27:05am'dt

n

name literal

'My Table'n

t

time constant

'9:25:19pm't

x

hexadecimal notation

'534153'x

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lrcon&docsetTarget=p0cq7f...

 


@tianerhu wrote:

tianerhu_0-1615240155141.png

What does the upperletter D mean  ? and why is the code wrong? Thank you.


 

ballardw
Super User

With pictures it is hard to tell but it appears to me that there is a space between the " and the D

Examine the lines below:

"01JAN1960" D
"01JAN1960"D

The first would be an error, the second is a date literal. Date literal is the way that you tell SAS you want to use the internal numeric representation of a date (or datetime or time value). The D could be lower case as could the month abbreviation. But there cannot be a space between the quote and the letter.

Example log from running code involving those two lines:

58   data junk;
59      x="01JAN1960" D;
                      -
                      22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>,
              =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |,
              ||, ~=.

60   run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      59:6
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.JUNK may be incomplete.  When this step was stopped there were 0
         observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


61
62   data junk2;
63      x="01JAN1960"D;
64   run;

NOTE: The data set WORK.JUNK2 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

The underscore under the letter D in the first bit is "unexpected" because of the space.

 

Pictures of proportional font text can be hard to tell but I think that is the issue in this case.

If you copy and run my code you will find the value of X in the Junk2 data set is indeed 0. 1 January 1960 is the base numeric value for dates and is day "zero".

 

tianerhu
Pyrite | Level 9
Thank you .

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 4354 views
  • 6 likes
  • 4 in conversation