Date: Sun, 30 Mar 2008 09:07:10 -0700
Reply-To: sbarry@SBBWORKS.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Scott Barry <sbarry@SBBWORKS.COM>
Organization: http://groups.google.com
Subject: Re: How can I write the sort program?Thanks!
Content-Type: text/plain; charset=ISO-2022-JP
On Mar 30, 10:12 am, ljm...@sohu.com wrote:
> code DATE CT
>
> 600000 20050105 21
> 600000 20050105 8
> 600000 20050105 61
> 600000 20050606 257
> 600000 20050606 103
> 600000 20051207 3491
> 600000 20051207 43
> 600000 20051207 873
> ......... ............ ......
>
> as the dataset, I want to split the the whole dataset into several
> small datasets that have the same date Obs. Because of the huge
> dataset actually, so it can't be sortted by some idiographic condition
> sentence $B!J (Bsuch as "date=20050105 $B!( (B" $B!K (B, or else, it will be a prodigious
> work.
> So, How can I write the program $B!) (B Thanks $B!* (B
Kind sir, you are working with the SAS language, for which prodigious
data manipulation and handling is a mere cake-walk, given some degree
of knowledge and experience with the language.
So, let's begin, post-haste --- consider using the SAS MACRO language
to generate your code, based on the example below;
options source source2 macrogen symbolgen mlogic nomprint;options
source source2 macrogen symbolgen mlogic nomprint;
data _your_input_sas_file_;
keep code date ct;
informat date yymmdd8. ; format date date9. ;
input code $ date ct;
if date = . then abort ;
cards;
600000 20050105 21
600000 20050105 8
600000 20050105 61
600000 20050606 257
600000 20050606 103
600000 20051207 3491
600000 20051207 43
600000 20051207 873
run;
%MACRO GENCODE;
%let by = code date;
%let nodupbreak = %scan(&by,-1,%str( ));
data _your_input_sas_file_view_ / view=_your_input_sas_file_view_;
set _your_input_sas_file_;
run;
proc sql noprint;
select count(distinct(date)) into :datecount from
_your_input_sas_file_view_;
select distinct(date) into :val1-:val%left(&datecount) from
_your_input_sas_file_view_;
quit;
%* show date values in the SASLOG. ;
%put _local_;
%* now loop to read and interleave each date, combining with previous
date obs. ;
%if &datecount %then %do i=1 %to &datecount;
proc sort data=_your_input_sas_file_view_ out=_temp_;
where date = "&&&val&i"D ; /* presumes you read up your date with a
date INFORMAT. */
by &by;
run;
data _your_input_sas_file_sorted_;
set _temp_
%if %sysfunc(exist(_your_input_sas_file_sorted_)) %then %do;
%* file will only exist *AFTER* the first DATA step pass. ;
_your_input_sas_file_sorted_;
by &by;
if first.&nodupbreak; /* remove duplicates - may not desire? */
%end;
; run;
proc delete data=_temp_;
run;
%end;
* add code to save new file out to perm data library location. ;
%MEND GENCODE;
%GENCODE;
If you have never used the SAS Macro language, you have some review
work ahead of you to learn the facility for this type of repetitive
task processing. The SAS support website is a great resource for
technical papers and helpful SAS coding examples, for you to consider.
Scott Barry
SBBWorks, Inc.
P. S. Remember to reply only to the group and not to the poster,
considering privacy and for the benefit of all subscribers. Thx, sbb
|