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"
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.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.