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
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 |
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 |
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 |
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 |
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 |
Which statement does not perform automatic conversions in comparisons?
how would you create multiple observations from a single observation? : Sas programming
you have a data set like this. data qqq; input name $ total; cards; qq 22 ww 33 qq 22 ee 44 rr 33 ww 44 ; run; and you want output like this......... name total qq 22 ww 44 Do it by data set step.
Name validation tools used in SAS
which features do you use to check the data validations and errors? : Sas-administrator
I use NOCUM/NOPERCENT option in the tables statement like this Proc freq data = deepak; tables x y /nocum nopercent; run; Here I get nopercent and nocum in the output only for variables x and y. How do i do it for all variables? Deepak
Explain what is the use of proc gplot?
What is the difference Using & and && in the macro variables
Explain the difference between using drop = data set option in set and data statement?
How will you assign all the variables of an dataset into a macro variable separated by a space? For example if a dataset has variables A,B,C. Assign them to a macro variable X as X=A B C
Identify statements whose placement in the DATA step is critical.
What Proc glm does?