Date: Sun, 29 Jan 2006 15:40:38 +0300
Reply-To: Mikhail Konovalov <ipmikon@mail.ru>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mikhail Konovalov <ipmikon@MAIL.RU>
Subject: Re: Inefficient data transformation
In-Reply-To: <443p69F6jrpU1@individual.net>
Content-Type: text/plain; charset=us-ascii
Hello Richard.
Sorry for stupid question, but why you need first SET statement? Your
code reads the dataset 3 times.
Regards, Mikhail
---------------------------------------------------
On Sunday, January 29, 2006 3:03:38 PM, Richard A. DeVenezia <rdevenezia@WILDBLUE.NET> wrote:
> Hari wrote:
>> Hi,
>>
>> (I had a problem to solve and I dont know how to use DATA steps to do
>> what I want to do. So, I used to solve the problem in a complicated
>> manner. I think Data step magic can be used to solve this problem
>> elegantly, please guide me for the same.)
>>
>> I have to export a SAS data file in to text format in such way that
>> each ID (in my case Market is ID) in my data file is grouped together
>> (sort on ID) and
>> just before the starting row of each ID a new row is inserted which
>> has numerical ID (equivalent to market)in first column and second
>> column has count of number of markets.
>>
>> So, if my starting SAS file (I have put commas between
>> variables/values) looks like the folowing :-
>>
>> InterCeptDumm,IndepVar1,IndepVar2,IndepVar3,DependentVar,Market
>> 54,23,1.45,65,89,"DSD"
>> 14,63,78.09,98,15,"DSD"
>> 98,63,89.34,76,17,"DSD"
>> 97,25,90.76,36,29,"DSD"
>> 76,43,6.45,23,98,"KUY"
>> 14,57,98.09,23,15,"KUY"
>> 65,46,89.04,76,17,"SET"
>> 98,87,89.23,71,37,"SET"
>> 102,24,79.98,67,56,"SET"
>>
>> Then I would like to see my Data file as
>>
>> InterCeptDumm,IndepVar1,IndepVar2,IndepVar3,DependentVar
>> 1,4
>> 54,23,1.45,65,89,"DSD"
>> 14,63,78.09,98,15,"DSD"
>> 98,63,89.34,76,17,"DSD"
>> 97,25,90.76,36,29,"DSD"
>> 2,2
>> 76,43,6.45,23,98,"KUY"
>> 14,57,98.09,23,15,"KUY"
>> 3,3
>> 65,46,89.04,76,17,"SET"
>> 98,87,89.23,71,37,"SET"
>> 102,24,79.98,67,56,"SET"
>>
>> In the above file , I have assigned a numeric ID of 1 to market "DSD"
>> and it is stored in the first column (IndepVar1) and the number of
>> rows for "DSD" is stored in second column
>> as frequency count.
> %let seed = 4101831;
> * fake data;
> data foo;
> do rowid = 1 to 1e4;
> array v value1-value5;
> do j = 1 to dim(v);
> v[j] = floor(100*ranuni(&seed));
> end;
> group = floor(5e3*ranuni(&seed));
> output;
> end;
> run;
> * prep for output;
> proc sort data=foo out=bar;
> by group;
> * output using Haris desired
> id, frequency
> introducer of each group -- using the double DO technique.
> ;
> filename myOut temp;
> data _null_;
> file myOut dsd dlm=',';
> set bar;
> by group;
> * find number of rows in each group;
> do _n_ = 1 by 1 until (last.group);
> set bar;
> by group;
> end;
> * output the groups introducer;
> put group= _n_=;
> * output the data of the group;
> do _n_ = 1 to _n_;
> set bar;
> put value1-value5;
> end;
> run;
> options noxwait xmin noxsync;
> x start "Review" NotePad "%sysfunc(pathname(myOut))";
> --
> Richard A. DeVenezia
> http://www.devenezia.com/
|