Help using Base SAS procedures

CNTLIN FORMATS

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

CNTLIN FORMATS

Hi I have difficulty in figuring when to and when not use things a sshowm below

Please help me figure this out

Thanks

proc sort data=diag(keep=id) out=encount nodupkey;
by id;
run;


DATA fmtDataset;
set encount (rename=(id=start));                        /*id is a numeric var*/
  label="yes";
  fmtname="ENCID";                                      /*How will I know if i have to enclose the fmt name in Quotes or No Quotes or to put a dollar sign leading the fmt name?????*/
  run;

PROC FORMAT CNTLIN=fmtDataset;
RUN;

DATA want;

  set clrt.order_med;

  if put(ID, ENCID.) = 'yes';                      /*How will I know if i have to put $ sign leading the format name or not..if i put in this case it says it has already been defined NUMERIC?????*/
   run;


Accepted Solutions
Solution
‎04-10-2013 03:04 PM
Trusted Advisor
Posts: 2,113

Re: CNTLIN FORMATS

In the first DATA step, the fmtname is a text string and must be in quotes.  The "$" is used if the variable to which the format will be applied later is a character data type.  See the documentation for PROC FORMAT for the data types of the CNTLIN data set.

In the second DATA step, ENCID. is the name of the format to be applied to ID; it is not in quotes.

Doc Muhlbaier

Duke

View solution in original post


All Replies
Solution
‎04-10-2013 03:04 PM
Trusted Advisor
Posts: 2,113

Re: CNTLIN FORMATS

In the first DATA step, the fmtname is a text string and must be in quotes.  The "$" is used if the variable to which the format will be applied later is a character data type.  See the documentation for PROC FORMAT for the data types of the CNTLIN data set.

In the second DATA step, ENCID. is the name of the format to be applied to ID; it is not in quotes.

Doc Muhlbaier

Duke

Super User
Super User
Posts: 6,495

Re: CNTLIN FORMATS

You can tell PROC FORMAT what type of format/informat you want to create by adding the TYPE variable to your CNTLIN dataset.

If ID variable is Numeric:

fmtname="ENCID";

type='N';

...

if put( ID, ENCID.) = 'yes';


If ID variable is character:

fmtname="ENCID";

type='C';

...

if put( ID, $ENCID.) = 'yes';

An easy way to test is to make a format and use CNTLOUT option to create a dataset and look at how SAS does it.

Super User
Posts: 17,743

Re: CNTLIN FORMATS

This is a good proc format reference:

http://www2.sas.com/proceedings/sugi30/001-30.pdf

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 320 views
  • 6 likes
  • 4 in conversation