Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tilde delimted output

Status
Not open for further replies.

nirmalraj

MIS
Apr 20, 2005
33
0
0
US
Hi

I have a raw data which has 20 observations and 10 variables. These 20 observations actually contain the same id number, say repeats of 5, that is each id number occurs 5 times. Of the 10 variables only certain variables are present for each observation.

Is it possible for me rollup the variables into 1 id number and basically make it contain in 4 observations with all the variables rolled up.
example:
x1 x2 x3 x4 x5 x6 x7 x8..
1 aaaa h g
2 bbbb t i
3 cccc j h o
4 aaaa w r e
5 bbbb u l z
6 aaaa r a x
7 .
8 .
9 .
10 .( etc)
11 .
. .
. .
.
.
.


Can some one tell me how to make this file appear only like
aaaa w h r r e a x
bbbb
cccc
dddd
eeee

will i get this using array?

Thanks,
Raj
 
Since you are not dealing with numeric data, the standard tricks don't work (retain summary). If you are sure that there are no duplicate values for your data points by ID value than split the dataset into 'skinny' datasets. Use the Output statement to output one variable plus the id column into their own datasets (narrow and skinny, hense the term)
Use proc sort to sort the data by ID than merge them back into the main dataset. There are a few more solutions but that is the easiest.

Here is an example:

Code:
*** Export values  ***;
data main(keep=x1) v2(keep=x1 x2) v3(keep=x1 x3)
     v4(keep=x1 x4) v5(keep=x1 x5) v6(keep=x1 x6) v7        (keep=x1 x7) v8(keep=x1 x8);
set master;
output main v2 v3 v4 v5 v6 v7 v8;
run;
*** Sort id data ***;
proc sort 
   data = main
   out  = mainnodup nodupkey;
   by x1;
run;
*** Sort value data ***;
proc sort
  data = v2
  out  = v2S;
  by x1;
run;
*** put the same sort in for each table ***;

...
  
data merge_data;
 merge mainnodup (in=in_main)
       v2        (in=in_v2) 
       v3        (in=in_v3)
       v4        (in=in_v4)
       v5        (in=in_v5)
       v6        (in=in_v6)
       v7        (in=in_v7)
       v8        (in=in_v8); 
by x1;
run;
 

Lets assume the value variable X1 is numeric. I only want to write a file out in tilde limited format and the variables rolled up.


77777~Raj~Sub~~~
77777~~84745834~~
77777~~~~~sas

say an output like this

77777~Raj~Sub~84745834~sas~

I think we have to use line hold specifier.

Thanks,
Raj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top