I'm got a file that includes performance info before and after a change. I want to be able to easily separate the before and after by date, so I added a new variable and am trying to mark PRE or POST change based on when the change was done. I'm using "If then" statement against date, but am only getting PRE in all columns. Here's what it looks like now:
Job;Procstep;Program;Stepname;Date;System;CPUTMX;Elapsed;CDate
ICL226ID;ICL226ID;GNC8317;STEP020;12DEC2017;SYSC;0.21;4.23;PRE
ICL226ID;ICL226ID;DFSRRC00;STEP010;12DEC2017;SYSC;57.61;1650.17;PRE
ICL226ID;ICL226ID;GNC8317;STEP020;14DEC2017;SYSC;0.23;2.35;PRE
ICL226ID;ICL226ID;GNC8317;STEP020;15DEC2017;SYSC;0.22;5.95;PRE
ICL226ID;ICL226ID;DFSRRC00;STEP010;15DEC2017;SYSC;58.11;1199.19;PRE
and what I'm looking for it do look like:
Job;Procstep;Program;Stepname;Date;System;CPUTMX;Elapsed;CDate
ICL226ID;ICL226ID;GNC8317;STEP020;12DEC2017;SYSC;0.21;4.23;PRE
ICL226ID;ICL226ID;DFSRRC00;STEP010;12DEC2017;SYSC;57.61;1650.17;PRE
ICL226ID;ICL226ID;GNC8317;STEP020;14DEC2017;SYSC;0.23;2.35;PRE
ICL226ID;ICL226ID;GNC8317;STEP020;15DEC2017;SYSC;0.22;5.95;POST
ICL226ID;ICL226ID;DFSRRC00;STEP010;15DEC2017;SYSC;58.11;1199.19;POST
Code I've tried is below:
Data _null_ ;
FILE DMAN1 DELIMITER =';' DROPOVER ;
if _n_=1 then put
'Job;Procstep;Program;Stepname;Date;System;CPUTMX;Elapsed;CD);
set extract ;
IF DATE <='14DEC2017' THEN CD='PRE';
else CD='POST';
put (job procstep program stepname newdate system cputmx elapsed CD)
(+0);
run ;
Appreciate the help.
I finally figured out why I was getting the variable date was uninitialized. I used format newdate earlier in the program. Thanks for getting me 99.9% there. Code is doing what I'm looking for.
If you run a PROC CONTENTS on the data set EXTRACT, what does it tell you about the DATE field? That is the key to coding the proper comparison.
Here is what I see with proc contents:
ALPHABETIC LIST OF VARIABLES AND ATTRIBUTES
# VARIABLE TYPE LEN FORMAT LABEL
8 NEWDATE NUM 8 DATE9.
In my output file it displays like this: 12DEC2017. I also tried format newdate DDMMYY10. Getting this result 12/12/2017 in my output file and then I tried coding the if statement like this:
if date LT EQ '14/12/2017' then Cdate='PRE';
else Cdate='POST';
The format that you apply doesn't impact the statements needed. I just had to know what was in the DATE variable. Here's the proper way to refer to a specific date:
IF DATE <='14DEC2017'd THEN CD='PRE';
The "d" immediately after the closing quote tells SAS that this is a date. You would use the same statement whenever the date variable is a legitimate numeric date, regardless of the format.
I was able to make the recommended change, but now I get a note that says: variable Date is uninitialized and it gives the DMAN1 file name.
Here's the out
DATA _NULL_ ;
FILE DMAN1 DELIMITER =';' DROPOVER ;
IF _N_=1 THEN PUT
'JOB;PROCSTEP;PROGRAM;STEPNAME;DATE;SYSTEM;CPUTMX;ELAPSED;CD';
SET EXTRACT ;
IF DATE <= '14DEC2017'D THEN CD='PRE';
ELSE CD='POST';
PUT (JOB PROCSTEP PROGRAM STEPNAME NEWDATE SYSTEM CPUTMX ELAPSED CD)
(+0);
RUN ;
NOTE: VARIABLE DATE IS UNINITIALIZED.
NOTE: THE FILE DMAN1 IS:
DSNAME=SOTS175.AF54125.ICLTEST9.CSV,
UNIT=3390,VOLUME=TSTP18,DISP=NEW,BLKSIZE=27998,
LRECL=27000,RECFM=VB,CREATION=2018/11/15
I finally figured out why I was getting the variable date was uninitialized. I used format newdate earlier in the program. Thanks for getting me 99.9% there. Code is doing what I'm looking for.
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!
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.