BookmarkSubscribeRSS Feed
kat6
Calcite | Level 5

I'm struggling through learning SAS here and I have a simple question that I cannot for the life of me figure out

I need to add a new column to my dataset that is in an existing permanent library with some conditions, specifically 

 

"7. Create a new column to indicate date issues."

• You create a new column named Date_Issues with a value of Needs Review to indicate that a row has a date issue. Date issues consist of the following: – a missing value for Incident_Date or Date_Received – an Incident_Date or Date_Received value out of the predefined year range of 2002 through 2017 – an Incident_Date value that occurs after the Date_Received value

 

and secondly, how does one create a permanent labels and formats?

Thank you!!

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Add new column to a data set in a permanent library, and a label and a format like this.

 

libname perm "\myfiles\subfolder1"; /* You need to specify the exact folder name for your data */
data perm.have2;
     set perm.have;
     if missing(date_received) then date_issues='Needs Review';
     label date_issues='Millard Fillmore';
     format date_received date9.;
run;

 

I leave it up to you to add the other conditions you mentioned.

 

The code above adds a new column and saves that new column in a new data set named HAVE2, this is good practice not to overwrite your original data set. If you really need it in the original data set HAVE, then just remove the 2.

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

See if you can use this as a template.

 

data permlib.want;
   set permlib.have;
   if year(Incident_Date) not in (2002 : 2017) or
      year(Date_Received) not in (2002 : 2017) or
      Incident_Date > Date_Received then Date_Issues = "Need Review";
   label Date_Issues = "Date Issues";
   format Incident_Date Date_Received date9.;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 13977 views
  • 0 likes
  • 3 in conversation