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;
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
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
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.
This is a good proc format reference:
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.