We are working based on 2 variables
/* To report first occurrence information */ Ex: Data medi; Input Gid $drug$ sdate edate ; Informat sdate edate date9. Format sdate edate date 9; Cards; G100 col5mg 12jan2006 16jan2006 G101 col5mg 13jan2006 17jan2006 G102 col5mg 13jan2006 17jan2006 G101 col10mg 21jan2006 25jan2006 G102 col5mg 23jan2006 27jan2006 G100 col10mg 23jan2006 29jan2006 G100 col15mg 01feb2006 05feb2006 G101 col10mg 03feb2006 07feb2006 G102 col15mg 03feb2006 06feb2006 G103 col10mg 03feb2006 04feb2006 ; Proc sort data = medi; By Gid; Run; Proc print data =medi; Run; Data first; Set medi; By Gid; If first .gid =1; Run; Proc print data =first; Run;
Ex; Data remain1; Set medi; By gid; If first.gid=0; Run; Proc print data=remain1; Run;
Ex: Data last; Set medi; By gid; If last.gid=1; Run; Proc print data=last; Run;
At TekSlate, we offer resources that help you in learning various IT courses. We avail both written material and demo video tutorials. To gain in-depth knowledge and be on par with practical experience, then explore SAS Training
Ex; Data remain2; Set medi; By gid; If last.gid=0; Run; Proc print data=remain2; Run;
Ex; Data firstlast Set medi; By gid; If first.gid=1 or last.gid =1; Run; Proc print data=firstlast; Run;
Ex; Data flast; Set medi; By gid; If first.gid=1 and last.gid=1; Run; Proc print data=flast; Run;
Ex; Data remain3; Set medi; By gid; If first.gid=0 and last.gid=0; Run; Proc print data=remain3; Run;
It can be used to calculate running total or cumulative tools.
Ex: Data market; Input month $sale; Cards; Jan 200 Feb 300 Mar . Apr 400 May 500 June 200 ; Data market 1; Set market; Retain total 0; Total = sum (total, sale); Run; Proc print data = market1; Run; To generate the output window with out using any procedure application(use with data set block) Ex; Data _null_; Set market; File print; Put month sale; Run;
(with variable and with out observations) using with data set block /* To delete required observations from existed data set*/ Ex: Data market ; Set market; If sale < 400 then delete; Run;
Ex: Data market1 ; Set market; delete; Run; Ex: Data market1 ; Set market; If sale >=400 ; Run;
Ex: Data demo; Length pid 4 age 3 Race $ 6; delete; Run;
For indepth knowledge on SAS, click on below
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.