Date: Mon, 18 Dec 2006 17:12:49 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: storing numbers of observations in splitted files
In-Reply-To: <s586c6bd.036@wbs.warwick.ac.uk>
Content-Type: text/plain; format=flowed
Wing ,
Unless you have a very and I do mean very compelling reason dont store them
separatly, just store them all together with a marker denoting type. SAS
has many tools available to you to sebset your data fast and easy like.
If it where me I would do the following:
1.) Get all data together in one data set with an extra var denoting Type.
2.) Run the data through another data set create and output counts. So
basically your holding yoru counts in a SAS Data Set. There are many cases
where holding information in a Data set is optimal over a bunch of macro
variables. An example of this is when you want to write code with no global
macro variables but need the flexability they offer.
Data Master ;
Set Test1 ( In = Test1 )
Test2 ( In = Test1 )
Test3 ( In = Test1 ) ;
If Test1 Then Type = 1 ;
If Test2 Then Type = 2 ;
If Test3 Then Type = 3 ;
Run ;
Proc Sort
Data = Master ;
By Type Date ;
Run ;
Data Counts ;
Set Master ;
By Type Date ;
Cnt + 1 ;
If Last.Date Then Do ;
Output ;
Cnt = 0 ;
End ;
Run ;
Toby Dunn
To sensible men, every day is a day of reckoning. ~John W. Gardner
The important thing is this: To be able at any moment to sacrifice that
which we are for what we could become. ~Charles DuBois
Don't get your knickers in a knot. Nothing is solved and it just makes you
walk funny. ~Kathryn Carpenter
From: Wing Tham03 <Wing.Tham03@PHD.WBS.AC.UK>
Reply-To: Wing Tham03 <Wing.Tham03@PHD.WBS.AC.UK>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: storing numbers of observations in splitted files
Date: Mon, 18 Dec 2006 16:50:01 +0000
Hi Toby,
I am sorry for not making this clear. I have three different files
test1,2,3. I want to split them indexed by their file names and date. I also
want to store their number of observations according to their types and
dates. I have hard-coded them below. Since there are 252 days in my data, it
will take a while for me to hardcode them. I am asking if there is a smarter
way to store the number of observations while i was splitting the data
according to their dates/dayid. Thanks.
Wing Wah
Data test1 ;
Infile Cards ;
Input date date9. dayid price ;
Cards ;
01jan2005 01 1.1
01jan2005 01 1.1
01jan2005 01 1.1
01jan2005 01 1.2
02jan2005 02 1.2
02jan2005 02 1.1
03jan2005 03 1.2
03jan2005 03 1.1
;
Run ;
Data test2 ;
Infile Cards ;
Input date date9. dayid price ;
Cards ;
01jan2005 01 1.2
01jan2005 01 1.3
01jan2005 01 1.4
01jan2005 01 1.5
02jan2005 02 1.1
02jan2005 02 1.3
02jan2005 02 1.2
03jan2005 03 1.1
;
Run ;
Data test3 ;
Infile Cards ;
Input date date9. dayid price ;
Cards ;
01jan2005 01 1.1
01jan2005 01 1.4
01jan2005 01 1.5
01jan2005 01 1.5
02jan2005 02 1.4
02jan2005 02 1.3
02jan2005 02 1.2
02jan2005 02 1.1
;
Run ;
%macro ndayid(data,name);
%global &name;
data _null_;
if 0 then set &data ndayid=count;
call symput ("&name",left(put(count,8.)));
stop;
run;
%mend ndayid;
%let C=test1@test2@test3;
%macro test;
%do ic=1 %to 3;
data %scan(&C,&ic,@);
set %scan(&C,&ic,@);
dayid=1000+dayid;
run;
proc sort data = %scan(&C,&ic,@)( keep = dayid ) out = %scan(&C,&ic,@)_w
nodupkey ; by dayid ; run ;
data _null_ ;
call execute ( "data " ) ;
do until ( eof ) ;
set %scan(&C,&ic,@)_w end = eof ;
call execute ( "%scan(&C,&ic,@)_P_" || put ( dayid, 4. ) ) ;
end ;
call execute ( "; set %scan(&C,&ic,@); select ( dayid ) ;" ) ;
eof = 0 ;
do until ( eof ) ;
set %scan(&C,&ic,@)_w end = eof ;
call execute ( "when (" || put (dayid, 4. ) || ") output " ||
"%scan(&C,&ic,@)_P_" || put (dayid, 4. ) || ";" ) ;
end ;
call execute ( "otherwise error ; end ; run ; " ) ;
stop ;
run ;
%end;
%mend;
%test;
%nobs(test1_p_1001,test1_1001_count);
%nobs(test1_P_1002,test1_1002_count);
%nobs(test1_P_1003,test1_1003_count);
%nobs(test2_p_1001,test2_1001_count);
%nobs(test2_p_1002,test2_1002_count);
%nobs(test2_P_1003,test2_1003_count);
%nobs(test3_p_1001,test3_1001_count);
%nobs(test3_p_1002,test3_1002_count);
%put quantity: &test1_1001_count;
%put quantity: &test1_1002_count;
%put quantity: &test1_1003_count;
%put quantity: &test2_1001_count;
%put quantity: &test2_1002_count;
%put quantity: &test2_1003_count;
%put quantity: &test3_1001_count;
%put quantity: &test3_1002_count;
Tham Wing Wah
Phone: +44-(0)24-765-22825
Mobile: +44-(0)79-468-44068
Email: Wing.Tham03@phd.wbs.ac.uk
Web: http://users.wbs.ac.uk/homepage/Wing.Tham03/wingwah
Doctoral Programme
Warwick Business School
Financial Econometrics Research Centre
University of Warwick
Coventry
CV4 7AL
UK
_________________________________________________________________
View Athlete’s Collections with Live Search
http://sportmaps.live.com/index.html?source=hmemailtaglinenov06&FORM=MGAC01