f



How to read a CSV file from right to left

Hi,

Can anyone tell me how to read a .CSV file from right to left? I know
its bit awkward as most of you will think as what difference it will
make.

Actually, my raw data is something like this:
ID,SOURCE,Var1,Var2......V275

The Id is unique but unfortunately the SOURCE contains values which are
comma separated. So my code to import to SAS go for a toss as for one
observation there can be three source while in other there can be 20
source. And in my raw file the values for each variable is not enclosed
within quotes("").

However I don't want this variable (SOURCE) in my analysis.

So I was wondering if I can read the data from V275 till V1 and drop the
rest. By conventional method I can read ID. In these two obtained data I
shall put a new ID which is nothing but the observation number and shall
merge with this new ID to get my desired Dataset.

Can anyone help me on this issue?


Regards,
Rajat
0
RMathur (16)
11/11/2005 1:37:00 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

2 Replies
469 Views

Similar Articles

[PageSpeed] 29

Hey Rajat
I think this code will due the work for you, if I understand your problem 
correctly.

data ReadData;
  length aline $1000;
  array vars (*) vars1 - vars5;
  infile "C:\test.txt" lrecl=1000;
  input aline;
  do i = -1 to -5 by -1;
    vars(dim(vars)-(abs(i)-1)) = input(scan(aline,i,","),best.);
  end;
  keep vars1 - vars5;
run;

/* this is the contents of the demo data */
/* Line #1 Id = 1, Source=2,3,4,5 Vars1=6  Vars2=7   Vars3=8   Vars4=9 
Vars5=10 */
/* Line #2 Id=11, Source=12        Vars1=13 Vars2=14 Vars3=15 Vars4=16 
Vars5=17 */
/* Line #3 Id=21, Source= 22,23  Vars1=24  Vars2=25 Vars3=26 Vars4=27 
Vars5=28 */
/*
1,2,3,4,5,6,7,8,9,10
11,12,13,14,15,16,17
21,22,23,24,25,26,27,28
*/

ap

"Rajat Mathur" <RMathur@INDUCTIS.COM> skrev i en meddelelse 
news:E68A1768216E394593B3A390F77725A403ACEBEE@MI8NYCMAIL06.Mi8.com...
> Hi,
>
> Can anyone tell me how to read a .CSV file from right to left? I know
> its bit awkward as most of you will think as what difference it will
> make.
>
> Actually, my raw data is something like this:
> ID,SOURCE,Var1,Var2......V275
>
> The Id is unique but unfortunately the SOURCE contains values which are
> comma separated. So my code to import to SAS go for a toss as for one
> observation there can be three source while in other there can be 20
> source. And in my raw file the values for each variable is not enclosed
> within quotes("").
>
> However I don't want this variable (SOURCE) in my analysis.
>
> So I was wondering if I can read the data from V275 till V1 and drop the
> rest. By conventional method I can read ID. In these two obtained data I
> shall put a new ID which is nothing but the observation number and shall
> merge with this new ID to get my desired Dataset.
>
> Can anyone help me on this issue?
>
>
> Regards,
> Rajat 


0
40971565 (1)
11/11/2005 9:30:04 PM
Rajat Mathur wrote:

> Actually, my raw data is something like this:
> ID,SOURCE,Var1,Var2......V275
>
> The Id is unique but unfortunately the SOURCE contains values which
> are comma separated. So my code to import to SAS go for a toss as for
> one observation there can be three source while in other there can be
> 20 source. And in my raw file the values for each variable is not
> enclosed within quotes("").
>
> However I don't want this variable (SOURCE) in my analysis.
>
> So I was wondering if I can read the data from V275 till V1 and drop
> the rest. By conventional method I can read ID. In these two obtained
> data I shall put a new ID which is nothing but the observation number
> and shall merge with this new ID to get my desired Dataset.
>
> Can anyone help me on this issue?

Try to decipher this fun sample.

data foo;
  retain id v1-v3 char1-char3;

  array cval[*] $32 char3-char1;
  array nval[*]   8 v1-v3;

  infile cards dsd dlm=',' _infile_=buffer1 ;
    file "NUL:" _file_=buffer2;

  input @1 id @;

  buffer1 = left(reverse(_infile_));
  input @1 (cval[*]) ($revers12.:) @;

  buffer2 = '';
  put @1 (char:)(',') @;

  buffer1 = buffer2;
  input @2 nval[*] ;

  drop char:;
cards;
1,a,b,c,3,4,5
2,a,z,5,4,3
3,a,b,c,d,e,f,12,34,56
run;

-- 
Richard A. DeVenezia
http://www.devenezia.com/


0
radevenz (1543)
11/12/2005 4:05:02 AM
Reply: