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:
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.