Hello SAS
I have de following database :
NOCONT | prod | DPD_0 | DPD0 | CDSITC1 | STARE1 | TOTAL11 | DPD_1 | DPD1 | Scadenta | dtcsts03 | DPD_WCS_risc | WCS | DPD_wcs | diferenta |
500000001 | CR | 0 | B0. 0 | 1 | A | 2925.07625 | 9 | B1. 1-3 | 22 | 10/22/2018 | 39 | 11/30/2018 | 39 | 0 |
500000005 | CR | 8 | B1. 1-30 | 1 | A | 667.75375 | 39 | B2. 31- | 69 | 11/30/2018 | 0 | |||
500000007 | CR | 0 | B0. 0 | 1 | A | 0.48 | 9 | B1. 1-3 | 22 | 10/22/2018 | 39 | 11/30/2018 | 39 | 0 |
DPD_WCS_risc represents DPD_1 + 30
DPD_ WCS represents the difference between WCS and DTCSTS03
diferente represents dpd_wcs_risc=dpd_wcs
normally in excel the results will be TRUE , FALSE or #n/a
after I run my code the results is 0 either is true or false , and in column DPD_WCS where the value is missing appear a dot (.)
both dpd_wcs_risc and DPD_risc are numerical
can someone please help me with a suggestion
I want to replace the missing values in DPD_wcs with #n/a or blank
I want to replace de diferenta values with true , false and #n/a or blank
here is my code :
data RRL;
set work.roll_rate_2;
DPD_WCS_risc=DPD_1+30;
WCS='30nov2018'D;
format WCS mmddyy10.;
DPD_wcs=wcs-dtcsts03;
diferenta=DPD_WCS=WCS;
run;
You can use IFC() function.
data roll_rate_2;
infile datalines dlm=',' dsd missover;
input NOCONT prod: $8. DPD_0 DPD0 : $8. CDSITC1 STARE1: $8.TOTAL11 DPD_1 DPD1 : $8.Scadenta dtcsts03 :mmddyy10. ;
format dtcsts03 mmddyy10. ;
datalines;
500000001,CR,0,B0. 0,1,A,2925.07625,9,B1. 1-3,22,10/22/2018
500000005,CR,8,B1. 1-30,1,A,667.75375,39,B2. 31-,,
500000007,CR,0,B0. 0,1,A,0.48,9,B1. 1-3,22,10/22/2018
;
run;
data RRL;
set work.roll_rate_2;
DPD_WCS_risc=DPD_1+30;
WCS='30nov2018'D;
format WCS mmddyy10.;
DPD_wcs=wcs-dtcsts03;
diferenta=ifc(DPD_WCS=DPD_WCS_risc,1,0);
run;
Note: Missing values for numerics are represented by (.) dot in SAS.
SAS is not Excel, the If's don't work the same, you need to use the else statement if the if statement evaluates false.
if a = b then c;
else d;
not a=b=c;
Hi there,
You can use PROC FORMAT to define how you want your variable to be printed.
proc format;
value myfmt .='n/a'
0='false'
other='true';
run;
Then to print the formatted data, you would do something like this:
proc print data=education; var mydiffval; #include all variables you want to see in the printed output format mydiffval myfmt.; run;
There's an example like this in the doc for PROC FORMAT.
Alternatively, if you want to save the formatted value, you can use a second DATA step to create a new data set and assign the format to your variable.
Hope this helps!
What the others said, and here my suggestion for the format code:
proc format;
value boolean
0,. = 'False'
other = 'True'
;
run;
data test;
input value;
format value boolean.;
cards;
0
1
.
-1
3
.3
;
run;
The format reproduces exactly what SAS considers to be true or false.
As for your code, I suggest a very slight change:
diferenta = (DPD_WCS = WCS);
This makes it obvious what is meant here.
You can use IFC() function.
data roll_rate_2;
infile datalines dlm=',' dsd missover;
input NOCONT prod: $8. DPD_0 DPD0 : $8. CDSITC1 STARE1: $8.TOTAL11 DPD_1 DPD1 : $8.Scadenta dtcsts03 :mmddyy10. ;
format dtcsts03 mmddyy10. ;
datalines;
500000001,CR,0,B0. 0,1,A,2925.07625,9,B1. 1-3,22,10/22/2018
500000005,CR,8,B1. 1-30,1,A,667.75375,39,B2. 31-,,
500000007,CR,0,B0. 0,1,A,0.48,9,B1. 1-3,22,10/22/2018
;
run;
data RRL;
set work.roll_rate_2;
DPD_WCS_risc=DPD_1+30;
WCS='30nov2018'D;
format WCS mmddyy10.;
DPD_wcs=wcs-dtcsts03;
diferenta=ifc(DPD_WCS=DPD_WCS_risc,1,0);
run;
Note: Missing values for numerics are represented by (.) dot in SAS.
thank you
sorry for my late answer , I have a lot of work to do , I'm at the very beginning of SAS.
I try to automatize some process that I have to do daily. it seems more hard in SAS but the time is priceless
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.