Date: Tue, 25 Aug 2009 07:42:42 -0500
Reply-To: "Data _null_;" <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Data _null_;" <iebupdte@GMAIL.COM>
Subject: Re: formats
In-Reply-To: <f527a661-dae3-42b9-ad7a-7d8f2d4dfcf4@p10g2000prm.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
This method just assumes that if a variable name matches a name in the
format library then that is the format that should be associated. You
could use macro or or macro variable but the PUT/%INC method is good
enough for this.
*** Make example data and format library;
libname study '.\study';
data study.class1;
set sashelp.class;
run;
data study.class2;
set sashelp.class;
run;
proc format;
value age other=[2.];
value $sex 'F'= 'Female' 'M'='Male';
run;
*** Format names and types;
proc catalog c=work.formats;
contents
out=fmtnames
(
keep = name type
rename = (type=fmttype)
index = (nametype=(name fmttype))
where = (type eq: 'F')
);
run;
proc print;
run;
*** Variable names and types;
proc contents noprint
data = study._all_
out = work.contents
(
keep=libname memname name type
)
;
run;
*** Hook'em up and ...;
*** Gen some code for PROC DATASETS;
filename FT85F001 temp;
data _null_;
file FT85F001;
set work.contents;
by libname memname;
if first.libname then put 'proc datasets library=' libname ';';
if first.memname then put +3 'modify ' memname ';';
select(type);
when(1) fmttype='FORMAT ';
when(2) fmttype='FORMATC';
otherwise;
end;
name = upcase(name); *** FORMAT name is UPCASE;
set work.fmtnames key=nametype/unique;
if _iorc_ eq 0 then do;
put +6 'format ' name @;
if type eq 2 then put '$' @;
put name +(-1) '.;';
end;
_error_=0;
if last.memname then put +6 'run;';
if last.libname then put +3 'quit;';
run;
%inc FT85F001 / source2;
On 8/24/09, rahul alawadhi <rahulalawadhi@gmail.com> wrote:
> i have a question regarding format. i have a library of user defined
> formats which i have created using proc format cntlin . . I need to
> use these user defined format in my dataset so that these formats can
> be displayed .
>
> situation is this : the dataset doesnt require all the user defined
> formats to be included in the dataset. only some of them are
> required.
> i have two questiosn to ask...how to add user defined formats to
> dataset and how to add only those formats which are required.
>
> /*varible fmt represents the variables , command represents the label
> format , radio_answer represents the code values
> fmt variables are there in other datasets with the same variable name
> to make link .*/
>
> data fm;
> set radio1 (rename=(label=fmt Radio_answer = start command=label));
> fmtname = catt(fmt,'_');
> keep fmt fmtname start label;
> run;
>
>
> proc format cntlin = fm;
> run;
>
> /*created macro variables */
>
> proc sql ;
> select distinct(fmtname) into :VA1-:VA9999
> from fm;
>
> select distinct(fmt) into :VF1-:VF9999
> from fm;
> select count(*) into :NUMVLL
> from fm;
> quit;
>
> /*dataset mix has the around 50 variables and some of the variables
> having the same variable as liested in user defined format */
>
> %macro runit1;
> data mix1;
> set mix;
>
> FORMAT %do i=1 %to &NUMVLL. ;
> &&VF&i &&VA&i.
> %end;
> ;
> run;
> %mend runit1;
>
> %runit1;
>
> i hope i am able to express my need properly. i guess there soemthing
> needs to be done in macro runit1( i believe) . is there any soultion
> as well for this...
>
> it would be great if anyone helps me out with this thing
>