Date: Thu, 19 Oct 2006 09:31:21 -0400
Reply-To: Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject: Re: Save formats permanently?
Content-Type: text/plain; charset=ISO-8859-1
On Thu, 19 Oct 2006 09:09:11 +0200, N. Knese <n.knese@GMX.DE> wrote:
>Hi,
>that's not exactly what I meant. An example: After having run the
macro I have two dataset containing the variables var (variable
name), value, N, percent with one ore more observations (depending
on the number of values and this is the problem). For dataset 1 the
values are for example 1=yes, 2=no, 3=missing, for dataset 2 the
values are 1=good, 2=better, 3=best. But I don't want to have the
values (numbers) in my combined table but the value labels (yes,
no, etc.). As I can only have one format for a variable (in this
case the variable value) I wondered if I couldn't save the labels
permanently (in an extra character variable for example).
>Anybody an idea?
>Nicole.
>-------- Original-Nachricht --------
>Datum: Wed, 18 Oct 2006 21:16:31 -0400
>Von: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
>An: SAS-L@LISTSERV.UGA.EDU
>Betreff: Re: Save formats permanently?
>
>> On Wed, 18 Oct 2006 09:48:33 +0200, N. Knese <n.knese@GMX.DE> wrote:
>>
>> >Hi all,
>> >
>> >due to the very helpful solutions to my last question (thanks to all
who
>> answered) another problem has come up in my program.
>> >I have got a macro
.......................
>
>--
>GMX DSL-Flatrate 0,- Euro* - Überall, wo DSL verfügbar ist!
>NEU: Jetzt bis zu 16.000 kBit/s! http://www.gmx.net/de/go/dsl
So you won't need to save those formats........
If you can consider replacing that macro, proc tabulate might
achieve almost all you seek, as in this example analysing two
frequencies in sashelp.class ( notice it uses an out= dataset )
proc tabulate data=sashelp.class out= classdata ;
class age sex;
table (age sex),(n pctn)*f=6.;
run;
proc print; run;
You would find that the out= dataset contains most of your information
However it provides a separate column for each class variable, and a
pointer (_type_) defining which class variable is relevant
To give you what you want, these can be reorganised in a datastep
without needing any macros.
Try code like:
%let class_list= age sex weight ;
proc tabulate data=sashelp.class out= classData ;
class &class_list ;
format age weight 2. ; * other formats maybe more relevant ;
table (&class_list),(n pctn)*f=6. ;
run;
data statistics( keep= class classVal N pctn_000 ) ;
length class $32 classVal $255 ;
format classval $32. ;
retain dsid ;
if _n_ = 1 then dsid = open( "classData", 'is' );
set classData end= last ;
pointer = index( _type_, '1' );
class = varname( dsid, pointer ) ;
classVal = vValueX( class );
if last then do; put _all_;
dsid= close( dsid );
end;
run;
proc print; run;
That produced
14:14 Thursday, October 19, 2006
PctN_
Obs class classVal N 000
1 Age 11 2 10.5263
2 Age 12 5 26.3158
3 Age 13 3 15.7895
4 Age 14 4 21.0526
5 Age 15 4 21.0526
6 Age 16 1 5.2632
7 Sex F 9 47.3684
8 Sex M 10 52.6316
9 Weight 51 1 5.2632
10 Weight 77 1 5.2632
11 Weight 83 1 5.2632
12 Weight 84 2 10.5263
13 Weight 85 2 10.5263
14 Weight 90 1 5.2632
15 Weight 98 1 5.2632
16 Weight ** 10 52.6316
Now you try with your datasets and class_list
Good Luck
Peter Crawford