DATA Step, Macro, Functions and more

Testing for missing character not working

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Testing for missing character not working

[ Edited ]

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;


Accepted Solutions
Solution
‎11-06-2015 04:06 PM
Trusted Advisor
Posts: 1,610

Re: Testing for missing character not working

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.),' ');

View solution in original post


All Replies
Solution
‎11-06-2015 04:06 PM
Trusted Advisor
Posts: 1,610

Re: Testing for missing character not working

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.),' ');

Contributor
Posts: 30

Re: Testing for missing character not working

Paige,

 

This was very helpful. Thank you very much.

 

Asim

Contributor
Posts: 55

Re: Testing for missing character not working

[ Edited ]

 

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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