Suppose there is a SAS dataset with following values -
Parent Child
A B
B C
D E
F G
G H
H I
and so on…..
This goes onto 1000s of observations/rows.
Now how do we identify from this dataset Grandparents and
Grandchildrens ?

Answers were Sorted based on User's Feedback



Suppose there is a SAS dataset with following values - Parent Child A B B C D E F G G H H I ..

Answer / sumit

Suppose the above dataset name is work.old.
Data new;
Set work.old (first obs = 2);
Run;

Proc sql;
Select Old.parent as grandfather, Old. Child as father,
new.child as grandchild from work.Old as old, work.new as
new
where old.child = new.parent;
quit;

Is This Answer Correct ?    17 Yes 0 No

Suppose there is a SAS dataset with following values - Parent Child A B B C D E F G G H H I ..

Answer / guest

data dx;
infile datalines dsd dlm=',';
input parent :$8. child :$8.;
datalines;
A,B
B,C
D,E
F,G
G,H
H,I
;;;;
run;

data dy(rename=(parent=grandfather child=father)) ;
merge dx(firstobs=2 in =a rename=(child=grandchild
parent=child ))
dx(firstobs=1 in =b );
by child;
if a and b;
run;
proc print;
var grandfather father grandchild;
run;

Is This Answer Correct ?    15 Yes 4 No

Suppose there is a SAS dataset with following values - Parent Child A B B C D E F G G H H I ..

Answer / altumish

A simple self Join:

data old;
input Parent $ Child $;
cards;
A B
B C
D E
F G
G H
H I
I J
J K
J L
P S
;

Proc sql;
Select Old.parent as grandfather, Old.Child as father,
new.child as grandchild from work.Old as old, work.Old as new
where old.child = new.parent;
quit;

Is This Answer Correct ?    1 Yes 0 No

Suppose there is a SAS dataset with following values - Parent Child A B B C D E F G G H H I ..

Answer / jayant

data tet;
input par $ child $;
datalines;
A B
B C
C D
E F
;
run;




data tet1;
set tet;
grand=lag(par);
drop par;
run;

Is This Answer Correct ?    0 Yes 1 No

Suppose there is a SAS dataset with following values - Parent Child A B B C D E F G G H H I ..

Answer / sas@freek

data family;
input parent $ child $;
datalines;
A B
B C
C D
D E
E F
F G
G H
H I
;
run;
data family_new(drop=parent child);
set family;
parent1=lag(parent);
child1=lag(child);
grand_child=child;
if _n_ ge 2;
run;

proc print data=family_new;
var parent1 grand_child;
run;

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More SAS Interview Questions

Hi All.I am looking for Good Institute who could Provide the online SAS BI+DI Training along with software.Primarily in Delhi/NCR or in Hyderabad Please help with name and contact number of concerned person!! Thanks in Advance! :)

1 Answers  


whenever we using the merging through data set merging ,we can get note in log like this "MERGE STATEMENT HAS MORE THAN ONE ONE DATASET BY REPEATED BY VAIABLES" but the output has come in good manner,whenever in in sql(full join) we can get cartion product.so How do overcome this problem in sql?

1 Answers   Accenture,


Describe 5 ways to do a “table lookup” in SAS?

0 Answers  


What is SAS? What are the functions does it performs?

0 Answers  


Explain data_null_?

0 Answers  






What are the main differences between sas versions 8.2, 9.0, 9.1?

4 Answers  


How to read an input file in sas?

0 Answers  


how we can call macros with in data step?

17 Answers   Allianz, ManPower,


What is Transaction...? And what are Comment, Roll back n Save point..?

2 Answers  


what is slowly changing dimension? : Sas-di

0 Answers  


What are symbol tables?Differemce between Local N Global Symbol tables.....

2 Answers   TCS,


What is your favorite all time computer book? Why?

0 Answers   Oracle,


Categories