LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 15 Apr 2003 05:11:11 -0700
Reply-To:     Rune Runnestoe <rune@FASTLANE.NO>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Rune Runnestoe <rune@FASTLANE.NO>
Organization: http://groups.google.com/
Subject:      Evaluating the sorting order in one and two columns
Content-Type: text/plain; charset=ISO-8859-1

/* Kan someone help med with the code where I have written it as pseudocode ? */

/*Making the table SAK, and filling it up with data*/ proc sql; create table test.sak (Saksnr varchar(8)); insert into test.sak values ('2000/122') values ('2000/123') values ('1999/981') values ('2001/585') values ('2001/586') values ('2001/584') values ('2001/587') values ('2000/124');

/*I am going to identify rows that are sorted wrong and rows that are sorted right in SAK. The sorting is demanded ascending.*/

data test.SortSak_right test.SortSak_wrong; set test.sak; /* Demands for the sorting of test.sak: For each row, compare the values of Saksnr with the value of all the rows beneath it. If any of the rows beneath is lower, then output test.SortSak_wrong. If none of the values in the beneath rows are lower, then output test.SortSak_right.

if input(substr(test.Saksnr,1,4)) on this row is greater than input(substr(test.Saksnr,1,4)) on the rows beneath, then output test.SortSak_feil; else if input(substr(test.Saksnr,1,4)) on this row is less than input(substr(test.Saksnr,1,4)) on rows beneath then output test.SortSak_rett; else if input(substr(test.Saksnr,1,4)) on this row is like input(substr(test.Saksnr,1,4)) på rader nedanfor then do; if substr(test.Saksnr,6,3) on this row is greater than substr(test.Saksnr,6,3) on other rows then output test.SortSak_wrong; else if substr(test.Saksnr,6,3) on this row is less than substr(test.Saksnr,6,3) on other rows then output test.SortSak_rett; end; */ run;

/*Making the table DOK, and filling it up with data*/ proc sql; create table test.dok (Saksnr varchar(8), Doknr num(3)); insert into test.dok values ('2001/585',1) values ('2000/123',1) values ('2000/123',3) values ('2000/123',2) values ('2000/122',1) values ('2000/122',2) values ('1999/981',1) values ('2001/586',2) values ('2001/586',1) values ('2001/586',3);

/*I am going to find the rows that are wrong and right sorted in DOK. The sorting is demanded to be ascending, first for the column Saksnr, then for the column Doknr. */ data test.SortDok_right SortDok_wrong; set test.dok; /* If input(substr(Saksnr,1,4)) on this row is greater than input(substr(Saksnr,1,4)) on the rows beneath then output test.SortDok_wrong; else if input(substr(Saksnr,1,4)) on this row is less than input(substr(Saksnr,1,4)) on the rows beneath then output test.SortDok_right; else if input(substr(Saksnr,1,4)) on this row is like input(substr(Saksnr,1,4)) on the rows beneath then do; If Doknr on this row is greater than Doknr on other rows with the same Saksnr then output test.SortDok_wrong; else if Doknr on this row is less than Doknr on other rows with the same Saksnr then output test.SortDok_right; end;

Is there a smarter or more simple programming logic for this task ? Can a while-loop or a for-loop be more suitable ? */

run;

/*Outprint from the table SAK*/ proc sql; title "Review of wrongly sortet rows in SAK"; select * from test.SortSak_wrong;

/*Outprint from the table DOK*/ proc sql; title "Review of wrongly sortet rows in DOK"; select * from test.SortDok_wrong;

Sincerely Rune Runnestoe


Back to: Top of message | Previous page | Main SAS-L page