DATA Step, Macro, Functions and more

converting dataset2formats

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

converting dataset2formats

1. if dataset having fmtname start and label variables only,how sas creating a format/in format with cntlin option of proc format?

2. type varible(optional) is for character/numeric , again why fmtname beginning with $ and  type is mentioning as 'c'.

both are in the same book and some one explain me ,please


proc format cntlin=exposure fmtlib;

run;

proc format;

  select @exp1944fmt @exp1945fmt;    informats to print

run;

proc format cntlin=control fmtlib;

run;

proc format;

  select $ICDFMT;  formats to print

run;


Accepted Solutions
Solution
‎08-29-2014 09:49 AM
Super User
Super User
Posts: 7,042

Re: converting dataset2formats

SAS has FORMATS and INFORMATS.  The first converts a value to a character string and the second converts a character string to a value.

Both can be either numeric or character.

When you reference them in SAS code you use $ before the name for character formats or informats.

When you reference them in the SELECT or EXCLUDE statement in PROC FORMAT you also add @ in front of the name to let it know that you mean an INFORMAT.

When you are trying to create them from a dataset you set the variable TYPE to indicate which you want to create.

N=Numeric format

C=Character format

I=Numeric informat

J=Character informat

Try this little program.

proc format ;

  value A 1='A' ;

  value $B '1'='B' ;

  invalue C 'C'=1 ;

  invalue $D 'D'='1' ;

run;

proc format fmtlib cntlout=formats;

run;

proc print ;

  var fmtname type start label ;

run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,949

Re: converting dataset2formats

I do not understand the question.  If you read in and create a format catalogue from a dataset, the type variable indicates if the format applied is character or numeric.  The c means that the format is a character format so the input and output would be character e.g:

$SEXC

'1' = 'Male'

'2' = 'Female'

For missing or n then this means a number to character:

SEXC

1 = 'Male'

2 = 'Female'

Contributor
Posts: 44

Re: converting dataset2formats

sorry for the trouble.

first program:                   for the  input dataset, sas created a informat with the given values.

second program:              for the input dataset, sas created a format  with the given values.

in both the cases I have given fmtname,start and label only,but one time sas created a format another time sas created informat

first program

proc format cntlin=exposure fmtlib; * here sas created a informat from the varibles( fmtname,start and end values)

run;

proc format;

  select @exp1944fmt @exp1945fmt; 

run;

second program

proc format cntlin=control fmtlib; * here sas created a format from the varibles (fmtname,start and end values)

run;

proc format;

  select $ICDFMT;

run;

Super User
Super User
Posts: 7,949

Re: converting dataset2formats

Yep, really not following you.  What is the difference between the exposure and control tables?  There shouldn't be that much difference between formats and informats, one is a method of reading in the data, the other for display.  Perhaps post the datasets, or a subset thereof so I can see the elements.

Solution
‎08-29-2014 09:49 AM
Super User
Super User
Posts: 7,042

Re: converting dataset2formats

SAS has FORMATS and INFORMATS.  The first converts a value to a character string and the second converts a character string to a value.

Both can be either numeric or character.

When you reference them in SAS code you use $ before the name for character formats or informats.

When you reference them in the SELECT or EXCLUDE statement in PROC FORMAT you also add @ in front of the name to let it know that you mean an INFORMAT.

When you are trying to create them from a dataset you set the variable TYPE to indicate which you want to create.

N=Numeric format

C=Character format

I=Numeric informat

J=Character informat

Try this little program.

proc format ;

  value A 1='A' ;

  value $B '1'='B' ;

  invalue C 'C'=1 ;

  invalue $D 'D'='1' ;

run;

proc format fmtlib cntlout=formats;

run;

proc print ;

  var fmtname type start label ;

run;

Contributor
Posts: 44

Re: converting dataset2formats

hi,

thanks for the reply.

I know  for creating a format from a dataset ,3 varibles are enough(fmtname,start,label). suppose my dataset not having a type column and I am using cntlin option for creating the format/informat. then how sas is creating the formats/informats.

I tried with your example only, used the cntlout option to create a dataset from the format and after that I deleted the formats in catalog and dropped the type column in dataset and again used the option cntlin option to create a format/informat from the dataset. then you can find the log here.

9290  proc format cntlin=dataset   fmtlib ;

NOTE: Format A has been output.

NOTE: Format B has been output.

NOTE: Format C has been output.

NOTE: Format D could not be written because it has the same name as an Institute-supplied format.

what is  error here?

Super User
Super User
Posts: 7,042

Re: converting dataset2formats

There is no error there. Since you did not provide a TYPE variable it tried to create them all as numeric formats.  If you do not want numeric formats then you need to provide the TYPE variable.

Contributor
Posts: 44

Re: converting dataset2formats

hi,

As per my understand,

if we are not mentioning type column it will create format default(numeric/character name depnds on the fmtname ) But if we mention (i,j) as types then it will create informats.

if my assumption is wrong,let me know.

Trusted Advisor
Posts: 3,212

Re: converting dataset2formats

Yep, as documented SAS(R) 9.4 Formats and Informats: Reference format D is a name already being used as SAS supplied

Base SAS(R) 9.4 Procedures Guide, Third Edition See restrictions: "The name of a user-defined format cannot be the same as the name of a format that is supplied by SAS."

It works as documented.                  No error, just keep attention to RTFM. 

---->-- ja karman --<-----
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 435 views
  • 0 likes
  • 4 in conversation