SAS Subsetting & Filtering Trick questions for Interview

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #49351
    rlochan2021
    Keymaster

    Every Tenth observation:-

    data abc;
    do p = 1 by 10 until (p >= (nobs-10));
    set xyz point=p nobs=nobs;
    output;
    end;
    stop;
    run;

    Proc sql;
    Create table abc as
    select * from xyz
    where (mod(monotonic () ,10))=0;
    quit;

    data abc;
    set xyz;
    if mod(_N_, 10) = 1;
    run;

    every second row in a data set:-

    data abc;
    set xyz;
    if mod(_n_,2) eq 0;
    run;

    or

    data abc;
    do i = 2 to nobs by 2;
    set xyz point=i nobs=nobs;
    output;
    end;
    stop;
    run;

    #49356
    rlochan2021
    Keymaster

    Creating a subset that contains only records with a certain value: In this case, your subset will keep the records that meet the criteria you specify. The criteria for keeping an observation is called the inclusion criteria.

    DATA New-Dataset-Name (OPTIONS);
    SET Old-Dataset-Name (OPTIONS);
    IF (insert conditions) THEN OUTPUT;
    RUN;
    Creating a subset that contains only records without a certain value: In this case, your subset will be all of the cases that remain after dropping observations with “disqualifying” values. The “disqualifying” values you specify are called the exclusion criteria.

    DATA New-Dataset-Name (OPTIONS);
    SET Old-Dataset-Name (OPTIONS);
    IF (insert conditions) THEN DELETE;
    RUN;

    source- https://libguides.library.kent.edu/SAS/SubsetData

    #49357
    rlochan2021
    Keymaster

    for docile:-

    proc rank data=abc
    out=xyz
    groups=10
    ties=low
    descending;
    var a2;
    ranks a1;
    run;

    for percentile-

    proc rank data=events
    out=test3
    groups=4
    ties=low
    descending;
    var score;
    ranks D_score;
    run;

    proc rank data=events
    out=test3
    ties=low
    descending;
    var score;
    ranks D_score;
    run;

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.