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 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';
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
I believe the problem is not with the IF statement, per se, but with understanding the difference between "execution-time" statements and "compile-time" statements. As explained in this documentation topic, the format statement is a "declarative" statement that only gets used by SAS one time in a program -- at compile time.
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001225397.htm

Perhaps you meant to create the variable NAALR_BND from NAALR_SCR by using the PUT function with the appropriate format. Something like this:
[pre]
data table5;
set table4;
length naalr_bnd $10;

if bsnss_unt_id = 702 then do;
naalr_bnd=put(naalr_scr, naalrs.);
end;
else if bsnss_unt_id = 803 then do;
naalr_bnd= put(naalr_scr, naalra.);
end;
else do;
naalr_bnd = naalr_scr; /* this will be an unformatted value */
end;
run;

[/pre]

If you could possibly have more than 2 values for bsnss_unt_id, you might want to code a final ELSE condition.
cynthia

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 557 views
  • 0 likes
  • 2 in conversation