BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Doc_Duke
Rhodochrosite | Level 12

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

3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12

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

Tom
Super User Tom
Super User

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.

Reeza
Super User

This is a good proc format reference:

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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