BookmarkSubscribeRSS Feed
satish123
Fluorite | Level 6

Dear all,

          If i,ve a dataset containing one variable with the obsevations 1-20 (say) from this dataset 2 subjects withdrawn 9, 16 (say) and i've choosen a random no. (say 18), now i need the output starting from 18 to 20% of data(when reached end of obs. then start from first like 18,20,1,2)

               thanks in advance.

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, I can't follow your logic.  Post have data (in terms of a datastep) and required output.  If you want loops then look at do loops. 

Patrick
Opal | Level 21

I don't understand how the first part of your question relates to the second part.

Below a code sample for the second part of your question how I understand it.

data have;

  do var=1 to 20;

    output;

  end;

  stop;

run;

data select(drop=_:);

  _start=ceil(ranuni(0)*_nobs);

  do _i=_start to _nobs;

      _counter+1;

    if _counter>4 then leave;

    set have nobs=_nobs point=_i;

    if _i=_nobs then _i=0;

    output;

  end;

  stop;

run;

satish123
Fluorite | Level 6

thanks, it could be very helpful.

satish123
Fluorite | Level 6

Giving decimal places and significant digits in SAS


Dear all,

i've a dataset like given bellow

                

ABCD
N363636
Mean9581.17289791.52621366.1106
SD2965.86262982.0749 398.3543
Geo_Mean9170.2867 2.0864674 1312.3213
CV13.95511 13.455669 0.159741

 

Now i need to give 3 decimal places for the variables 'B' & 'C', and 5 significant digits for the variable 'D'. But these decimal places and significant digits should not be applyed for observations of 'N'. i had tried many things like format, length and etc. but it didn't work well. the output should be like given bellow.


ABCD
N363636
Mean9581.1729791.5261366.1
SD2965.8622982.074398.35
Geo_Mean9170.2862.086 1312.3
CV13.955 13.4550.15974


i'm excited to find is it really possible? if so, can anyone tell me how? or it is possible by transforming the variables?

Thanks in advance

Ksharp
Super User

The most direct way is changing these variables into character variables .

The alternative way is using proc format or proc report + call define().

Xia Keshan

Ksharp
Super User

data have;

  do var=1 to 20;

    output;

  end;

  stop;

run;

data select;

array x{0:999999} _temporary_;

n=-1;

do until(last);

  set have end=last;

  n+1;x{n}=var;

end;

do i=18 to 21;

  want=x{mod(i,20)}; output;

end;

keep want;

stop;

run;

Xia Keshan

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 6 replies
  • 3178 views
  • 1 like
  • 4 in conversation