BookmarkSubscribeRSS Feed
NewUserFrank
Calcite | Level 5
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';
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
It's quite sufficient to post a question/issue in only one forum.

Scott Barry
SBBWorks, Inc.
monei011
Calcite | Level 5
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

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