BookmarkSubscribeRSS Feed
krg1140
Calcite | Level 5

I have a task that reads as:

 

"Create a new indicator variable to identify years where a restatement was issued.  If FILE_DATE is greater than 0, RESTATEMENT should equal 1 and otherwise should be 0."

 

So basically I need to create a new variable titled "restatement". FILE_DATE is currently, for example, in the format of 10MAR2021, but if there is no "file date" then it is set as "." 

 

What kind of function can I set and under what parameters/syntax to create a new variable that says if the file_date does have ANY date in it then to assign the new variable a "1" but if there is no date then set is as a "0"

1 REPLY 1
ballardw
Super User

SAS comparisons, such at > , < , LE and such will return 1 for "true" and 0 for false.

So in a data step something like:

 

data want;

    set have;

    indicator = (file_date>0);

run;

 

However your "requirement" says "If FILE_DATE is greater than 0" which is not the same as " if there is no date then set is as a "0"  ". Unless you mean File_date=0 is supposed to be equivalent to "no date".

If you mean that you have actual missing values then test the provided code. "Missing" is less than an any value so is not ">0".

Another concern, if you have dates are any of them prior to the year 1960? If so are they "> 0" ??? Numerically dates in SAS are stored as the number of days from 1 Jan 1960. So dates prior to 1 Jan 1960 are negative numbers and 0 is 01JAN1960. If you need to consider dates prior to 1960 then

 

data want;
    set have;
    indicator = not missing(file_date);
run;

would be more appropriate.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

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
  • 1 reply
  • 346 views
  • 0 likes
  • 2 in conversation