BookmarkSubscribeRSS Feed
SuryaKiran
Meteorite | Level 14

I was struck with this problem. Here is my code-->

proc format library=RMTWORK;

value $sex 'M'='Male'

'F'='Female'

;

Run;

options fmtsearch=RMTWORK;

data RMTWORK.one;

set sashelp.class;

format sex sex. ;

run;

 

When I open the created dataset and see it has 'M' and 'F' values but, It is supposed to have 'Male' and 'Female' in the output dataset.

 

Capture.PNG

 

When I run

Proc print data=rmtwork.one;

run;

It shows the formated values.

Capture3.PNG

Why did the dataset 'one' didn't show the user defined format values.

I'm using SAS EG 5.1 running on grid(sas9.3).

Thanks,
Suryakiran
23 REPLIES 23
Shmuel
Garnet | Level 18

you missed a $ sign and maybe need add length to it:

 

data RMTWORK.one;

set sashelp.class;

format sex $sex6. ;

run;

ChrisNZ
Tourmaline | Level 20

 

You must use parentheses.

options fmtsearch=(RMTWORK);

 

Doing this, it works for me.

 

aaa1.PNG

 

 

 

 

 

 

SuryaKiran
Meteorite | Level 14

Updated the code but, the problem is same

 

proc format library=RMTWORK;
value $sex 'M'='Male'
'F'='Female'
;
Run;

options fmtsearch=(RMTWORK);
data RMTWORK.one;
set sashelp.class;
format sex $sex6. ;
run;

Proc print data=rmtwork.one;
run;

Thanks,
Suryakiran
SuryaKiran
Meteorite | Level 14

Yes. Its on remote server.

Thanks,
Suryakiran
Kurt_Bremser
Super User

@SuryaKiran wrote:

Updated the code but, the problem is same

 

proc format library=RMTWORK;
value $sex 'M'='Male'
'F'='Female'
;
Run;

options fmtsearch=(RMTWORK);
data RMTWORK.one;
set sashelp.class;
format sex $sex6. ;
run;

Proc print data=rmtwork.one;
run;


Please post the complete log of this code piece.

SuryaKiran
Meteorite | Level 14

Here is the complete log:

 

1                                                          The SAS System                           08:40 Thursday, October 20, 2016

1          %_eg_hidenotesandsource;
1528  %_eg_hidenotesandsource;
1534  %_eg_hidenotesandsource;
1550 
1551 
1552  proc format library=RMTWORK;
1553  value $sex 'M'='Male'
1554  'F'='Female'
1555  ;
2                                                          The SAS System                           08:40 Thursday, October 20, 2016

NOTE: Format $SEX is already on the library.
NOTE: Format $SEX has been written to RMTWORK.FORMATS.
1556  Run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds
     

1557 
1558  options fmtsearch=(RMTWORK);
1559  data RMTWORK.one;
1560  set sashelp.class;
1561  format sex $sex6. ;
1562  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set RMTWORK.ONE has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
     

1563 
1564  Proc print data=rmtwork.one;
1565  run;

NOTE: There were 19 observations read from the data set RMTWORK.ONE.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
     

1566 
1567  %_eg_hidenotesandsource;
1579 
1580 
1581  %_eg_hidenotesandsource;
5         

Thanks,
Suryakiran
Kurt_Bremser
Super User

Hmm. Do a

libname rmtwork list;

and please post the NOTE: from the log.

 

But I just had another idea. Could it be that you have an identically named format elsewhere (especially in your WORK.FORMATS catalog) that overrides your newly created format?

Start a blank session, do not create the format, but use it. If that causes no error, you need to look where the other instance of the format is stored.

SuryaKiran
Meteorite | Level 14

libname rmtwork list;

 

Here is my log:

1                                                          The SAS System                           08:40 Thursday, October 20, 2016

1          %_eg_hidenotesandsource;
1585  %_eg_hidenotesandsource;
1591  %_eg_hidenotesandsource;
1607 
1608  libname rmtwork list;
NOTE: Libref=   RMTWORK
      Scope=    Program
      Access=   TEMP
      Levels=   1
        -Level 1-
      Engine=   V9
      Access=   TEMP
      Physical Name= /work/dev_work/SAS_work266802C0002A_p1sasgrid03
      Filename= /work/dev_work/SAS_work266802C0002A_p1sasgrid03
      Inode Number= 61542
      Access Permission= rwxr-xr-x
      Owner Name= suryakiran
      File Size (bytes)= 512
1609 
1610  %_eg_hidenotesandsource;
1622 
2                                                          The SAS System                           08:40 Thursday, October 20, 2016

1623 
1624  %_eg_hidenotesandsource;
5         

 

 

When I started with new session and used the format it showed error:

1543  data RMTWORK.one;
1544  set sashelp.class;
1545  format sex $sex. ;
                 -----
                 484
NOTE 484-185: Format $SEX was not found or could not be loaded.

Thanks,
Suryakiran
Kurt_Bremser
Super User

Now I'm positively stumped. Since not even one of the SAS people reading here has chimed in, I suggest putting this to SAS technical support. You might have uncovered a bug in the way the grid reads and applies formats.

SuryaKiran
Meteorite | Level 14

Yes KurtBremser, It seems like a bug. I tried different ways to figure it out. But, everything failed. Check this code and output:

 

proc format library=RMTWORK;

value $sex 'M'='Male'

'F'='Female';

run;

options fmtsearch=(RMTWORK);

data RMTWORK.ONE;

set sashelp.class;

format sex $sex. ;

gender=put(sex,$sex.);

run;

Capturec.PNG

 

 

Thanks,
Suryakiran
Tom
Super User Tom
Super User

 

When I started with new session and used the format it showed error:

Sounds like you do not fully understand how formats work.  When you permanently attach a format to variable, by using a FORMAT statement in a DATA step for example, then all it does it store the format name in the metadata of the dataset. It does not store the format defintion.  Those live separately in a format catalog.  When SAS wants to find a user defined format it searches the catalogs defined in the FMTSEARCH option.

 

So when you start a new session you need to make sure that in that new session you have set the FMTSEARCH option so that SAS can find the format that is attached to your variable.

 

 

SuryaKiran
Meteorite | Level 14

Hi Tom,

I'm running my program in sas session. My problem is format is applied but it shows 'M' 'F' values in sex column instead of 'Male' 'Female'.

I tried the same code in different environment it worked. Even for ChrisNZ it worked but it did't work in my environment.

 

I want a dataset like this

one.png

 

But my dataset looks like this even after I applied the format.

 

Capturec.PNG

Thanks,
Suryakiran
Tom
Super User Tom
Super User

In the session where it doesn't work try testing the value of the FMTSEARCH option.

%put %sysfunc(getoption(fmtsearch));

And also test that it works for PROC PRINT or other SAS tool instead of EG tool.

 

If that shows proper search path such that your user defined format can be found and PROC PRINT does in fact find the format and use it, then if EG still does not show the format when browsing the data it sounds like an issue specific to EG.  Perhaps you are using EG with a version of SAS that your EG version does not fully support?  

 

You should rasie a ticket with SAS support and see if they can find out why it doesn't work.  

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
  • 23 replies
  • 5579 views
  • 0 likes
  • 5 in conversation