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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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