BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Unstefan
Calcite | Level 5

Hello SAS

I have de following database :

NOCONTprodDPD_0DPD0CDSITC1STARE1TOTAL11DPD_1DPD1Scadentadtcsts03DPD_WCS_riscWCSDPD_wcsdiferenta
500000001CR0B0. 01A2925.076259B1. 1-32210/22/20183911/30/2018390
500000005CR8B1. 1-301A667.7537539B2. 31-  6911/30/2018 0
500000007CR0B0. 01A0.489B1. 1-32210/22/20183911/30/2018390

 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;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

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.

Thanks,
Suryakiran

View solution in original post

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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;

mebass
SAS Employee

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!

Kurt_Bremser
Super User

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.

SuryaKiran
Meteorite | Level 14

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.

Thanks,
Suryakiran
Unstefan
Calcite | Level 5

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: 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!

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
  • 5 replies
  • 4521 views
  • 1 like
  • 5 in conversation