My SAS Tutorials

Wednesday, 3 April 2013

SAS INTERVIEWS CONCEPTUAL QUESTIONS VII


We have a SAS data set:


data one;
input visit $ pt;
datalines;
v1 101
v1 102
v2 101
v2 102
v3 103
v3 101
;
run;

Required Output:



                                  Obs       visit    _101    _102    _103

                                  1              v1          1       1       .
                                  2             v2           1       1       .
                                  3             v3           1       .       1

Program:


data two;
set one;
drop i;
array a[3] _101 _102 _103;
do i=1 to dim(a);
a[i]=1;
end;
run;
proc transpose data=two out=three (drop=_name_);
by visit;
id pt;
run;
data four;
set three;
by visit;
if first.visit;
run;
proc print;
run;



Can anyone help me in write more efficient program than this as we are solving it by using three different steps?

Now prepare your Base SAS and Advance SAS Certification Exams with Online Mock tests:  http://exam.sankhyana.com

For training related info kindly mail us at info@sankhyana.com
www.sankhyana.com

4 comments:

  1. data one;
    set one;
    new=int(pt/100);
    run;

    proc transpose data=one
    out=two(drop= _NAME_)
    prefix=_;
    by visit;
    var new;
    id pt;
    run;

    ReplyDelete
  2. proc transpose data=one out=two(drop=_name_);
    id pt;
    var visit;
    by visit;
    run;


    data two;
    set two;

    if _101 ne ' ' then _101 = '1';
    if _102 ne ' ' then _102 = '1';
    if _103 ne ' ' then _103 = '1';

    run;

    ReplyDelete
  3. hi below code will works

    data two;
    set one;
    drop i;
    do i=1 to pt;
    a=1;
    end;
    run;

    proc transpose data=two out=three (drop=_name_);
    by visit;
    id pt;
    run;

    Thanks & Regards
    Vamshi

    ReplyDelete
  4. data two;
    set one;
    drop i;
    do i=1 to pt;
    a=1;
    end;
    run;
    proc print;
    run;

    proc transpose data=two out=three (drop=_name_);
    by visit;
    id pt;
    run;

    Thanks & Regards
    Vamshi

    ReplyDelete