- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello
How do I write matched and non-matching observations from merged dataset to different new data sets
I am trying to write a single program where I get two data sets; one for the matched, 2nd for the unmatched. Having a problem with the nomatch08 data set.
Data results.08 (output=results.nomatch08);
Merge Books.input08a
(In=Input08a)
Books.input08b (In=Input08b);
By Id;
If Input08a=1 and Input08b=1; output;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Data results.match08
results.nomatch08;
Merge Books.input08a (In=Input08a)
Books.input08b (In=Input08b);
By Id;
If Input08a and Input08b then output results.match08;
else output results.nomatch08;
run;
1. List both output data sets on the DATA statement - no parenthesis required
2. Add the OUTPUT to your IF statement and the name of the data set you want it written out to
3. Fix name of matched data set - names cannot start with a number (results.08 is not a valid SAS data set name).
@Toybeck11 wrote:
Hello
How do I write matched and non-matching observations from merged dataset to different new data sets
I am trying to write a single program where I get two data sets; one for the matched, 2nd for the unmatched. Having a problem with the nomatch08 data set.
Data results.08 (output=results.nomatch08);
Merge Books.input08a
(In=Input08a)
Books.input08b (In=Input08b);
By Id;
If Input08a=1 and Input08b=1; output;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Data results.match08
results.nomatch08;
Merge Books.input08a (In=Input08a)
Books.input08b (In=Input08b);
By Id;
If Input08a and Input08b then output results.match08;
else output results.nomatch08;
run;
1. List both output data sets on the DATA statement - no parenthesis required
2. Add the OUTPUT to your IF statement and the name of the data set you want it written out to
3. Fix name of matched data set - names cannot start with a number (results.08 is not a valid SAS data set name).
@Toybeck11 wrote:
Hello
How do I write matched and non-matching observations from merged dataset to different new data sets
I am trying to write a single program where I get two data sets; one for the matched, 2nd for the unmatched. Having a problem with the nomatch08 data set.
Data results.08 (output=results.nomatch08);
Merge Books.input08a
(In=Input08a)
Books.input08b (In=Input08b);
By Id;
If Input08a=1 and Input08b=1; output;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot. It worked.
How do I exclude all variables that begin with "ex" from results.nomatch08? Same program?
Thanks for your help.
Data results.matcho8 results.nomatch08;
Merge
cert.Input08a (In=Input08a)
cert.Input08b (In=Input08b);
By Id;
If Input08a=1 and Input08b=1 then output results.matcho8;
else output results.nomatch08;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
(Exclude all variables that begin with "ex" from results.nomatch08). the last statement is giving error.
Data results.match08 results.nomatch08;
Merge
cert.Input08a (In=Input08a)
cert.Input08b (In=Input08b);
By Id;
If Input08a=1 and Input08b=1 then output results.match08;
else output results.nomatch08; drop='ex:';
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your DROP statement is incorrect syntax wise.
You can use the data set options on the DATA statement but I'm not sure that takes wildcards, so if you have another naming convention you may be able to do that or otherwise you need to create that list ahead of time and there are ways. But if you have a naming convention that isn't needed.
So do you have a naming convention besides just ex?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm working on a practice exam. this is all the question says:
a. Combine data sets cert.input08a and cert.input08b by matching values of the ID variable.
b. Write only observations that are in both data sets to a new data set named results.match08.
c. Write all other non-matching observations from either data set to a new data set named results.nomatch08.
o Exclude all variables that begin with "ex" from results.nomatch08.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
If none of those work for you then you'll have to dynamically generate the list but that's usually not requirement for the base exam, possibly the advanced one though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Data results.match08 results.nomatch08;
Merge
cert.Input08a (In=Input08a)
cert.Input08b (In=Input08b);
By Id;
If Input08a=1 and Input08b=1 then output results.match08;
else output results.nomatch08;
drop=ex: ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data rm nrm(drop=ex:);
merge dadw(in=a) famx(in=b);
by id;
if a and b then
output=rm;
else output=nrm;
run;