Help using Base SAS procedures

Make Format from DataSet

Reply
New Contributor
Posts: 3

Make Format from DataSet

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
Respected Advisor
Posts: 4,173

Re: Make Format from DataSet

Posted in reply to PeterSchwennesen
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
Respected Advisor
Posts: 3,799

Re: Make Format from DataSet

Posted in reply to PeterSchwennesen
[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]
New Contributor
Posts: 3

Re: Make Format from DataSet

Posted in reply to data_null__
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
PROC Star
Posts: 7,487

Re: Make Format from DataSet

Posted in reply to PeterSchwennesen
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
New Contributor
Posts: 3

Re: Make Format from DataSet

Hi Art
I still do not quite understand, but I hope it will com.
I get the overall meaning.
But thanks
Peter Schwennesen
PROC Star
Posts: 7,487

Re: Make Format from DataSet

Posted in reply to PeterSchwennesen
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
Ask a Question
Discussion stats
  • 6 replies
  • 194 views
  • 0 likes
  • 4 in conversation