How to pick every third row in SAS

Sdílet
Vložit
  • čas přidán 22. 08. 2024
  • How to use _n_, mod function, nobs= and point=. to keep the observations . If you like this video, please feel free to like, share, comment and subscribe.. For any queries, please contact us at smarttech089@gmail.com

Komentáře • 21

  • @9356079
    @9356079 Před 3 lety

    Nicely explained👍

  • @ajaykushwaha4233
    @ajaykushwaha4233 Před rokem

    Excellent

  • @letsbuildstuff7766
    @letsbuildstuff7766 Před 3 lety

    very nicely explained

  • @og_in_ohio9605
    @og_in_ohio9605 Před 4 lety +1

    Forgive me if I don't understand this correctly, but at 9min 20 seconds the data step has the do loop above the set statement. I would expect this to make a number of PDV's. Also the tot variable is not defined until you are in the loop.

    • @kiranvenna
      @kiranvenna  Před 4 lety

      POINT= option inside a DO loop is designed to assign a different value to the POINT= variable on each iteration, so that random rows can be accessed. So do loop is not looping set statement but it is changing the value of variable in point=. NOBS =tot is set at compile phase and do loop works during execution phase, as tot variable is already created/available it can be used before set statement. Hope I am clear in explaining this.

  • @adityabatra8894
    @adityabatra8894 Před 3 lety

    All patient has 5 visit date . the query is the visit date is greater than previous visit date

    • @kiranvenna
      @kiranvenna  Před 3 lety

      Please give a sample input and output so that I understand your problem better and help you

  • @shravyajasti1432
    @shravyajasti1432 Před 4 lety +1

    Hello sir, Can you do a video on RETAIN statement ?
    And can you make some advanced macros videos ?
    Thanks!

    • @kiranvenna
      @kiranvenna  Před 4 lety

      I will try. Please checkout this advance Macro Video czcams.com/video/63mWty9aZsA/video.html

  • @GoduruSaiteja
    @GoduruSaiteja Před rokem

    Hi Sir, May i know the reason, Why you did kept =0 in the MOD function (If Mod(_n_,3)=0). Can you please tell me sir. i

    • @kiranvenna
      @kiranvenna  Před rokem

      Mod function gives us reminder. Remainder = 0 here means means _n_ is completely divisible by 3.

    • @GoduruSaiteja
      @GoduruSaiteja Před rokem

      @@kiranvenna ok Thank you so much for the clarification and replied

  • @mummanenivanaja7116
    @mummanenivanaja7116 Před 3 lety

    Hello sir ,if we have column like this var=xxxx yyy zz ,then I need where ever x is there then it has been replaced by and in the place of y i need 2 and in the place of z I need 3 ,this values are in single column ,so how can I do it ?? Pls can u suggest me ,

    • @kiranvenna
      @kiranvenna  Před 3 lety

      I am.sorry it is not completely clear what you are asking for

    • @mummanenivanaja7116
      @mummanenivanaja7116 Před 3 lety

      @@kiranvenna I have one column and value is like this "xxx yy z " so in this place I need 1 in the place of xxx and 2 in the place of yy and 3 in the place of z ,so finally 1 2 3 is my out put ,can u pls explain the logic

    • @kiranvenna
      @kiranvenna  Před 3 lety +1

      One way to do this.
      data abc;
      a="xxx yy z";
      length B $10;
      retain B;
      do i=1 to countw(a);
      b=catx(" ", b, put(i, 3.));
      end;
      drop a i;
      rename b=a;
      run;

  • @mummanenivanaja7116
    @mummanenivanaja7116 Před 3 lety

    If we need 1 st and last record along with this every row of 3 record ,pls could u explain how can we extract??

    • @kiranvenna
      @kiranvenna  Před 3 lety +4

      just need to include 1 and last record in do loop. try below query
      data class;
      do p=1, 3 to n-1 by 3, n;
      set sashelp.class point=p nobs=n;
      output;
      end;
      stop;
      run;

    • @mummanenivanaja7116
      @mummanenivanaja7116 Před 3 lety +1

      Thank you sir.

  • @ajaykushwaha4233
    @ajaykushwaha4233 Před rokem

    Anyone can help, what to to to keep records from 1, 4,7,10 n so on.

    • @kiranvenna
      @kiranvenna  Před rokem +1

      Try this.
      data a;
      set sashelp.class;
      justforcheck=_n_;
      if mod(_n_, 3)=1;
      run;