DATA Step, Macro, Functions and more

Format questions

Reply
Frequent Contributor
Posts: 77

Format questions

What is F10.4 format? I can't find any web page in SAS explaining this format.


Second, a dataset has user defined formats attached to some variables. How to "decode" these user defined formats?


Thanks in advance!
N/A
Posts: 0

Re: Format questions

Hi, MarcTC.
for qustion 2;
you can specify 'format (var);'
here's a example.
data test;
input a @@;
format a dollar5.1;
cards;
1 2 3
;
run;
proc print;
run;
data akari;
set test;
format a;
run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Format questions

Posted in reply to deleted_user
Decoding a user-defined SAS format: check the PROC FORMAT documentation, you have either CNTLOUT= (then PROC PRINT) or more simply you can use FMTLIB to print the contents of a SAS format.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

proc format fmtlib site:sas.com
Frequent Contributor
Posts: 77

Re: Format questions

I only have a SAS dataset, no original Catalog which created the user-defined formats used in the dataset. Isn't FMTLIB only applied for Catalog only?

Here is a more detailed description about my dataset:

The data looks like:

Student Rank
Tom Top 10
Mary Top 20
Joe Top 10
Nancy Top 30

Rank is a numeric variable, but associated with a user-defined format. That is why you see those strings Top 10, Top 20.. when viewing the dataset. I want to know what are the underlying numeric values corresponding to each string. That is what I meant by "decoding a format".
SAS Super FREQ
Posts: 8,868

Re: Format questions

Ah, that's not how I interpreted "decode". To "remove" a user-defined format for the purpose of running a report, you can use a NULL format statement, such as shown below. Basically, you list the variable on a FORMAT statement and then do NOT put a format name after the variable name.

cynthia
[pre]
proc print data=mydata;
format rank;
run;
[/pre]
Frequent Contributor
Posts: 77

Re: Format questions

Posted in reply to Cynthia_sas
Hmm...you still don't get what I mean.


Suppose:

Rank=1 => being formated as "Top 10"
Rnak=2 => being formated as "Top 20"
Rank=3 => being formated as "Top 30"
....

I want to find out this relationship/mapping.
SAS Super FREQ
Posts: 8,868

Re: Format questions

That's what FMTLIB does -- it shows the mapping from the values to the label. If the FMTLIB is being used when you do a PROC PRINT (and the format shows up in a PROC CONTENTS), then FMTLIB will show the mapping, not exactly in the form you show, but close enough.

cynthia
Frequent Contributor
Posts: 77

Re: Format questions

Posted in reply to Cynthia_sas
You are smarter and can read the SAS syntax page.


I tried several different combinations and nothing works. One of them is:

proc format library=work.mydataset fmtlib;
select $rank;
run;
SAS Super FREQ
Posts: 8,868

Re: Format questions

Hi:

OK..for your SAS dataset. If you run PROC CONTENTS, do you see that $RANK is listed as the format???

If yes, then try:
library=library or
library=work

in your PROC FORMAT statement. The chances are good that your folks who built the format took the default and stored the user defined format in a format catalog called "LIBRARY" or in "WORK" -- I know, it seems redundant to have LIBRARY=LIBRARY, but that's one of the "simple" ways that folks have defined their own format catalogs over the years.

You cannot put your dataset name in the LIBRARY= option.

If you run a PROC CONTENTS and do NOT see $RANK listed as the format being used for the field, then it is probable that the format used to create the RANK variable might not be available to you.

cynthia
Frequent Contributor
Posts: 106

Re: Format questions

Posted in reply to Cynthia_sas
Shouldn't the OP be looking for the numeric format RANK much rather?

I.e.

....
select rank ;
SAS Super FREQ
Posts: 8,868

Re: Format questions

Posted in reply to Robert_Bardos
A PROC CONTENTS should tell him whether the format is character or numeric and whether there is a format in current use. That's why I keep asking whether he's run PROC CONTENTS.

cynthia
Super User
Posts: 10,046

Re: Format questions

Hi.
proc format + cnlout option to output the format contents into a dataset.
I remember it has mentioned by Art C at before post.


Ksharp
Respected Advisor
Posts: 3,799

Re: Format questions

> What is F10.4 format? I can't find any web page in
> SAS explaining this format.

It appears that F is the name of the format most know as w.d

[pre]
203 data _null_;
204 x = 1;
205 format x 10.4;
206 format = vformat(x);
207 put 'NOTE: ' format=;
208 run;

NOTE: format=F10.4
[/pre]
SAS Super FREQ
Posts: 8,868

Re: Format questions

Hi:
As it shows here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000199377.htm

The "F" format is an alias for the simple w.d (width/decimal) that can be applied to numeric variables.

The whole list of formats by category is here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a001263753.htm

To see a list of all the user-defined formats (or selected ones) stored in a format library, use the FMTLIB option with PROC FORMAT:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473464.htm

cynthia
Ask a Question
Discussion stats
  • 13 replies
  • 531 views
  • 0 likes
  • 7 in conversation