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

Hi,

 

By applying a character format, I am creating a character based field. One of the values in the newly created character field is ' ' (single space between quotes). However, when I try to test for this value in an "if condition", nothing seems to work. I have tried applying compress function, missing function. The code snippet is below.

 

Can you please advise me how can I check if the value is ' '?

 

Many thanks in advance!

Asim

 

 

Character Format

------------------------

proc format library = mapbook;
    value $FG_Format
        'AMBAC' = 'AMBAC'
        'MBIA' = 'NPFG (MBIA subsidiary)'
        'FGIC-MBIA' = 'NPFG (MBIA subsidiary)'
        'FGIC'    = 'NPFG (MBIA subsidiary)'
        'XL Capital' = 'Syncora (formerly XL Capital)'
        'FSA' = 'Assured Guarantee Municipal (formerly FSA)'
        'HUD Cap Funds - AGM' = 'Assured Guarantee Municipal (formerly FSA)'
        other =' ';
run;

 

Creation of Character Field by applying the Character format

----------------------------------------------------------------------------------

data merged6;
    ...

    length FG_3rd_Party $50;   

    ...

 

    FG_3rd_Party = Recourse_Group;
    format FG_3rd_Party $FG_Format.;

run;

 

Test for missing Value in the Character Field

-------------------------------------------------------------

 

    if FG_3rd_Party in (' ') then
        put FG_3rd_Party;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The code you have doesn't check the formatted value of the variable for a space, it checks the actual unformatted value of the variable for a space.

 

If you want to test to see if the space is in the formatted value, you can use something like:

 

b=find(put(FG_3rd_Party,$FG_Format.),' ');

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

The code you have doesn't check the formatted value of the variable for a space, it checks the actual unformatted value of the variable for a space.

 

If you want to test to see if the space is in the formatted value, you can use something like:

 

b=find(put(FG_3rd_Party,$FG_Format.),' ');

--
Paige Miller
asimraja
Fluorite | Level 6

Paige,

 

This was very helpful. Thank you very much.

 

Asim

JoshB
Quartz | Level 8

 

While you "see" the formatted value, you haven't actually changed the variable in the dataset. You'll need to use something like

FG_3rd_Party = put(Recourse_Group,$FG_Format.);

You'll see/be able to test for missing values at that point.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1390 views
  • 0 likes
  • 3 in conversation