BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sathya66
Barite | Level 11

Hi,

I am trying to merge with index variables  but when merge finished the output table doesn't have the index table.

here  my A  table has index variables . I want see the same result in TEST table  also(with index variables).

 

data test;

merge a(in=a) b(in=b);

by id;

if a=b then do;

if name ne ' ' then name='XXXX';

end;

if a then output;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
10 REPLIES 10
Kurt_Bremser
Super User

If you want to have an index for a newly created dataset, use proc datasets to add it to the dataset. Indexes are not automatically created.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep and what the output should look like.  At a guess:

if a=b then do;

Does not do what you think it does, you may mean, if a and b, i.e. if record is in both datasets. 

I can't really tell you anything else without seeing some data.

Kurt_Bremser
Super User

@RW9 wrote:

Post test data in the form of a datastep and what the output should look like.  At a guess:

if a=b then do;

Does not do what you think it does, you may mean, if a and b, i.e. if record is in both datasets. 

I can't really tell you anything else without seeing some data.


The funny thing is that this works, as a = b = 0 can never happen. Although I prefer to use if a and b;

sathya66
Barite | Level 11

yes It is working , but I will change to if a and b. here Id is the index varable

 

sathya66
Barite | Level 11
sorry,
here base table is A table and A table is B table
Kurt_Bremser
Super User

Running this:

data test;
merge sascomm.base(in=a) sascomm.a(in=b);
by id;
if a=b then do;
  if name ne ' ' then name='XXXX';
end;
if a then output;
run;

proc print data=sascomm.base noobs;
proc print data=sascomm.a noobs;
proc print data=test noobs;
run;

after uploading your datasets, I see no problems at all:

  id    name

   1    qq   
   2    aa   
   3    ss   
   4    ss   
   5    dd   
   6    dff  
   7    vff  
   8    gggg 
   9    ggggg
  10    rrr  
  11    sss  
  12    ssss 
  13    dddd 
  14    sssss
                

       id

        2
        5
        6
        7
       10
                

  id    name

   1    qq   
   2    XXXX 
   3    ss   
   4    ss   
   5    XXXX 
   6    XXXX 
   7    XXXX 
   8    gggg 
   9    ggggg
  10    XXXX 
  11    sss  
  12    ssss 
  13    dddd 
  14    sssss

 

sathya66
Barite | Level 11
yes, sascomm.base table is an index table on ID.(didn't upload index table).
when we perform merge test table doesn't create an index table.
sathya66
Barite | Level 11

 

data sascomm.base(index=(id));

set sascomm.base;

run;

data test;
merge sascomm.base(in=a) sascomm.a(in=b);
by id;
if a=b then do;
  if name ne ' ' then name='XXXX';
end;
if a then output;
run;

 

when we perform this. test table is not creating the index table . I want to get the index table also.

Kurt_Bremser
Super User

As I already said, use proc datasets to create an index table for a newly created dataset. Index tables are not automatically created.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 5764 views
  • 0 likes
  • 3 in conversation