BookmarkSubscribeRSS Feed
PeterSchwennesen
Fluorite | Level 6
Hi All
I am brand new to this SAS thing. I have a question about making Formats. I have tried make a Format from a explaining, but in this Format I also like to have a "Other=" entry to mark all values outside the defined range, but I do not know how to do. This is the code; but all values go to "???" and not just the number 3 as I expected.

data t1;
input key name $;
cards;
1 A
2 B
; run;

data t2 (drop=key name);
set t1;
fmtname='fmt';
start=key;
label=name;
run;

proc format cntlin=t2;
value fmt other='???';
run;

data y;
a=3; b=2; c=1;
put a a fmt.;
put b b fmt.;
put c c fmt.;
run;

any help? or are there another post desribing how to do?

Peter Schwennesen
7 REPLIES 7
Patrick
Opal | Level 21
Hi

A fast way to get the code right is to use SAS Enterprise Guide (4.3 - not sure about earlier versions).

There you find under "Tasks/Data/Create Format from Dataset..." a wizard which creates you the code.

HTH
Patrick
data_null__
Jade | Level 19
[pre]
data t1;
input key name $;
cards;
1 A
2 B
; run;

data t2;
retain fmtname 'fmt' type 'n' hlo ' ';
length label $64;
set t1(rename=(key=start name=label)) end=eof;
output;
if eof then do;
call missing(start);
label = 'Outside Range';
hlo = 'O';
output;
end;
run;
proc format cntlin=t2 cntlout=cntlout;
run;
proc print data=cntlout;
run;
[/pre]
PeterSchwennesen
Fluorite | Level 6
Hi Data_NULL_
Thanks. Now it is Working.
However it is a little cryptic code for me,
I am not Quite sure what the function of "call missing(Start); hlo='O' is.
but thanks,
Peter Schwennesen
art297
Opal | Level 21
Peter,

DataNull was simply putting in the conditions to include an extra format record in case any of your values fall outside of the defined formats.

You'll notice that both of those statements are only run after all of the records have been read (i.e., at the end of the file).

call missing(Start) simply set the value of start to missing and hlo='O' sets the value of hlo to 'O' or 'other'

HTH,
Art
---------
> Hi Data_NULL_
> Thanks. Now it is Working.
> However it is a little cryptic code for me,
> I am not Quite sure what the function of "call
> missing(Start); hlo='O' is.
> but thanks,
> Peter Schwennesen
PeterSchwennesen
Fluorite | Level 6
Hi Art
I still do not quite understand, but I hope it will com.
I get the overall meaning.
But thanks
Peter Schwennesen
art297
Opal | Level 21
Peter,

A nice (I think) explanation of the process can be found at:
http://www2.sas.com/proceedings/sugi26/p236-26.pdf

HTH,
Art
> Hi Art
> I still do not quite understand, but I hope it will
> com.
> I get the overall meaning.
> But thanks
> Peter Schwennesen
DrAbhijeetSafai
Pyrite | Level 9

Hi Peter,

 

Greetings!

 

I also had the similar question as how to create a format from a dataset. I found following two sources useful. 

 

1) SAS Documentation: https://documentation.sas.com/doc/en/vdmmlcdc/8.1/proc/n1e19y6lrektafn1kj6nbvhus59w.htm

 

 2) A paper with title "Creating a Format from Raw Data or a SAS® Dataset " by Wendi L. Wright : https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/068-2007.pdf

 

The paper is of 2007 and in documentation, a table named 'The CTLR Dataset' gives lot of information. However, if there is any better way of understanding it, please let me know. 

 

Thanking you,

Yours sincerely,

 

- Dr. Abhijeet Safai

Dr. Abhijeet Safai
Associate Data Analyst
Actu-Real

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
  • 7 replies
  • 1321 views
  • 7 likes
  • 5 in conversation