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;
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;
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;
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;
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.
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;
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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.