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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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