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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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