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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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