Joining (merging) previous a previously created table non-logically(no key)

Reply
Contributor
Posts: 30

Joining (merging) previous a previously created table non-logically(no key)

I want add a variable to a table but I want to do it non logical....I selected the distinct values of a column and I want them to appear in only the first n rows and not be logically matched to observations or using a key...What would be the easiest way?

Super User
Super User
Posts: 7,711

Re: Joining (merging) previous a previously created table non-logically(no key)

Well,

proc sql;

     create table WANT as

     select     HAVE.*,

                    LIST.VALUES

     from       (select *,MONOTONIC() as N from HAVE) HAVE

     left join      (select *,MONOTIC() as N from (select distinct VALUES from HAVE)) LIST

     on          HAVE.N=LIST.N;

quit;

I haven't checked this as no test data provided, but something similar should be ok.   You are basically assigning a row number to each table and merging based on that.

Respected Advisor
Posts: 4,812

Re: Joining (merging) previous a previously created table non-logically(no key)

Use a simple datastep:

/* Example data */

data a;

do x = 9 to 1 by -1; output; end;

run;

data b;

do y = "X", "Y", "Z"; output; end;

run;

/* Merge by reading one from each set */

data c;

set a;

if not endB then set b end=endB;

output;

call missing(y);

run;

proc print data=c noobs; run;

   x    y

   9    X

   8    Y

   7    Z

   6

   5

   4

   3

   2

   1

PG

PG
Contributor
Posts: 30

Re: Joining (merging) previous a previously created table non-logically(no key)

for some reason neither are accomplishing this task on my data

Super User
Posts: 11,118

Re: Joining (merging) previous a previously created table non-logically(no key)

Post some example data and expected result.

Contributor
Posts: 30

Re: Joining (merging) previous a previously created table non-logically(no key)

1574636.2578987TBD12012-04210.200005.00
215615896.2120999TBD12013-01260.266673.75
315613964.3935277TBD12012-02820.266673.75
415611998.2752766TBD12013-02300.266673.75
5156101065.868534TBD12013-00470.266673.75
6125101508.230495TBD12012-01960.250004.00
712581631.255777TBD12009-01220.250004.00
812571706.900386TBD12009-02740.250004.00
97471953.118538TBD12012-03250.285713.50
107461981.413955TBD12013-02140.285713.50
116362539.431428TBD12011-03210.833331.20
126342889.548451TBD12011-03340.833331.20
136333410.332587TBD12010-03150.833331.20
146323451.533757TBD02013-00890.833331.20
156313473.987399TBD12012-01270.833331.20
164214204.3416TBD12013-00260.250004.00
17151154608.061858TBD12012-01321.000001.00

The second column contains sample sizes that are linked to each observation,

I selected them distinctly

proc sql; create table stratasummary as

select distinct _Nsize_ as Nsizesummary

from sampled

order by strata;

quit;

115
24
36
47
512
615
75

the first columns are the obs columns...

And now I want to append it non-logically, it seems every SAS command that I know to combine involves logic and some sort of key...

Ultimately, what I want is: where the column is combined with no logic or manipulated logix

11574636.2578987TBD12012-04210.200005.00
24615896.2120999TBD12013-01260.266673.75
36613964.3935277TBD12012-02820.266673.75
47611998.2752766TBD12013-02300.266673.75
5126101065.868534TBD12013-00470.266673.75
6155101508.230495TBD12012-01960.250004.00
75581631.255777TBD12009-01220.250004.00
8.571706.900386TBD12009-02740.250004.00
9.471953.118538TBD12012-03250.285713.50
10.461981.413955TBD12013-02140.285713.50
11.362539.431428TBD12011-03210.833331.20
12.342889.548451TBD12011-03340.833331.20
13.333410.332587TBD12010-03150.833331.20
14.323451.533757TBD02013-00890.833331.20
15.313473.987399TBD12012-01270.833331.20
16.214204.3416TBD12013-00260.250004.00
17.1154608.061858TBD12012-01321.000001.00
Super User
Posts: 9,867

Re: Joining (merging) previous a previously created table non-logically(no key)

data want;

merge stratasummary sampled;

run;

Ask a Question
Discussion stats
  • 6 replies
  • 211 views
  • 6 likes
  • 5 in conversation