Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help! SAS Format not working 1

Status
Not open for further replies.

cosmid

Programmer
Feb 14, 2008
73
US
I am writing a data entry screen using FSEdit. I need to use Informat and Format to get make data entry easier and the data more clear. But somehow, when I use format, it always reads the format stored in the SAS temporary folder, work folder. I have assigned the format to a permanent library in different ways but it just always reads the format from the SAS temporary folder. Does anyone know how to fix this?

Thank you for your time and help!
 
Here are the different codes that I have used:

----------------------------------------------------
libname mydata 'C:\SAS\programs\data';
libname library 'C:\SAS\programs\data';
proc format library = library;
value $code 'A','a'='GAS' 'B','b'='CONVENIENCE' 'C','c'='Bakery';
run;
data mydata.test; length BName $ 35 Date 6 A $ 1 B $ 1 C $ 1;
informat Date mmddyy6.;
format Date mmddyy10. A $code. B $code. C $code.;
run;

proc fsedit; run;

proc print data=mydata.test;
run;
-----------------------------------------------------
The format are not stored as permanent but temporary. For example, if I change the code to the following:

proc format;
value $code 'A','a'='GAS1' 'B','b'='CONVENIENCE1' 'C','c'='Bakery1';
run;

If I run the code, all format are ended with 1. And if I delete all the data I created and change the code again to the original and create all the data again:

libname library 'C:\SAS\programs\data';
proc format library = library;
value $code 'A','a'='GAS' 'B','b'='CONVENIENCE' 'C','c'='Bakery';
run;

If I run a proc print or fsedit, the format is actually the one earlier. Where everything end in 1. for 'A' or 'a' it would be GAS1 and not GAS. My question is, how do I make the code to reference the format that I created?

Thanks!!!
 
SORRY! WHAT I TYPED ON THE ABOVE THREAD DOESN'T MAKE MUCH SENSE. I REWORDED MY QUESTION AND HERE THEY ARE:

----------------------------------------------------
libname mydata 'C:\SAS\programs\data';
libname library 'C:\SAS\programs\data';
proc format library = library;
value $code 'A','a'='GAS' 'B','b'='CONVENIENCE' 'C','c'='Bakery';
run;
data mydata.test; length BName $ 35 Date 6 A $ 1 B $ 1 C $ 1;
informat Date mmddyy6.;
format Date mmddyy10. A $code. B $code. C $code.;
run;

proc fsedit; run;

proc print data=mydata.test;
run;

If I run this code, the format are saved as they are, 'a' for GAS, etc.
------------------------------------------------------------

If I change the code from above to the following:

proc format;
value $code 'A','a'='GAS1' 'B','b'='CONVENIENCE1' 'C','c'='Bakery1';
run;

If I run the code here, all format are ended with 1. For 'a', it would be GAS1. So everything works out ok so far. But, if I delete everything I write, including the data I created and write a new program, the one below, it will actually reference the format here in this portion.
------------------------------------------------------------

Here are the code after I delete everything from above, including the format cat, data file, etc.

libname mydata 'C:\SAS\programs\data';
libname library 'C:\SAS\programs\data';
proc format library = library;
value $code 'A','a'='GAS' 'B','b'='CONVENIENCE' 'C','c'='Bakery';
run;
data mydata.test; length BName $ 35 Date 6 A $ 1 B $ 1 C $ 1;
informat Date mmddyy6.;
format Date mmddyy10. A $code. B $code. C $code.;
run;

proc fsedit; run;

proc print data=mydata.test;
run;



Ok. Now if I run the code, I should get 'a' for GAS and 'b' for CONVENIENCE right? But I actually got 'a' for GAS1 and 'b' for CONVENIENCE1 and 'c' for BAKERY1. My question is, how to write a format where your code will use the format that you've created? Becausae it doesn't matter how many new files I created, they will all use the format in the 2nd attempt. The only thing that works is the Date format. But that is not user defined. How do you use a user defined format?


Thanks!!!
 
Ok I think I get your problem. SAS uses the local format catalog unless you tell it different. Your proc format saves to the work folder. When you close SAS and open the session again you will get a new format catalog.

First pick a folder that the finished FSEdit screen will have access to. Then set a sas libref to that location and create your 'static' format. Then in an autoexec file, set the options statement to also look at your static format.

Here is an example of how I would do it;

Code:
libname myfmt 'C:\SAS\programs\data';
proc format lib = myfmt ;
  value $code 
   'A','a' = 'GAS'
   'B','b' = 'CONVENIENCE'
   'C','c' = 'Bakery'
   ;
run;
Then use the OPTIONS statement to let SAS 'know' where to find this new format library.

Code:
libname myfmt 'C:\SAS\programs\data';
options fmtsearch=(myfmt work);

data mydata.test; 
  length BName $35
         Date   6
         A     $1
         B     $1
         C     $1
         ;

  informat Date mmddyy6.;
  format Date mmddyy10. A B C $code.;
run;
    
proc fsedit
  data = mydata.test;
run;

proc print 
 data = mydata.test;
run;
The fmtsearch option tells SAS to first look in the MYFMT libref for a MYFMT.FORMATS catalog then look in the work folder and then the LIBRARY libref.

I hope that this helps you.
Klaz
 
Thank you Klaz! That was a very detailed reply! I can't believe it!

Thank you so much!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top