Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Help with a if then statement.

Reply
New Contributor
Posts: 2

Help with a if then statement.

I'm a new user to SAS and am in the process of updating someone elses code, for the most part no issues, except this one which has left me puzzled. I'm running a data step that is adding new fields (only showing one in my example) and applying a formats run earlier as part of a Proc Format process.

Issue: When the process runs, only one of the formats is pickedup. Meaning, all records regardless of bsnss_unt_id get the same format . . . any help would be appreciated

data Table5;
set Table4;

naalr_bnd = naalr_scr;

/* groups naalr band */
if bsnss_unt_id = 702 then do;
format naalr_bnd naalrs.;
end;
else if bsnss_unt_id = 803 then do;
format naalr_bnd naalra.;
end;

run;
endrsubmit;

proc format;
value naalra
0 - 0 = '01_000-000'
1 - 349 = '02_001-349'
350 - 354 = '03_350-354'
355 - 359 = '04_355-359'
360 - 364 = '05_360-364'
365 - 369 = '06_365-369'
370 - 374 = '07_370-374'
375 - 379 = '08_375-379'
380 - 384 = '09_380-384'
385 - 389 = '10_385-389'
390 - 394 = '11_390-394'
395 - 399 = '12_395-399'
400 - 404 = '13_400-404'
405 - 409 = '14_405-409'
410 - 414 = '15_410-414'
415 - 419 = '16_415-419'
420 - 424 = '17_420-424'
425 - 429 = '18_425-429'
430 - 434 = '19_430-434'
435 - 439 = '20_435-439'
440 - high= '21_440-999 '
other = 'missing';

value naalrs
0 - 384 = '01_000-384'
385 - 399 = '02_385-399'
400 - 414 = '03_400-414'
415 - 424 = '04_415-424'
425 - 459 = '05_425-459'
460 - high= '6_460+'
other = 'missing';
Super Contributor
Super Contributor
Posts: 3,174

Re: Help with a if then statement.

It's quite sufficient to post a question/issue in only one forum.

Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 12

Re: Help with a if then statement.

The format statement is not able to be issued conditionally the way you have done.

if bsnss_unt_id = 702 then do;
format naalr_bnd naalrs.;
end;
else if bsnss_unt_id = 803 then do;
format naalr_bnd naalra.;
end;

You need to do something like

if bsnss_unt_id = 702 then do;
newvar=put( naalr_bnd, naalrs.);
end;
else if bsnss_unt_id = 803 then do;
newvar=put( naalr_bnd naalra.);
end;
Ask a Question
Discussion stats
  • 2 replies
  • 136 views
  • 0 likes
  • 3 in conversation