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;
As I already said, use proc datasets to create an index table for a newly created dataset. Index tables are not automatically created.
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.
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.
@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;
yes It is working , but I will change to if a and b. here Id is the index varable
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
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.
As I already said, use proc datasets to create an index table for a newly created dataset. Index tables are not automatically created.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.