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.

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 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.

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
  • 3 replies
  • 795 views
  • 0 likes
  • 3 in conversation