InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What are the different joins in proc SQL and unlike data step why SQL don’t require sorting before joins? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Answer» SET and Merge are two very vital statements in SAS. Let US UNDERSTAND by taking 2 tables ‘one’ and ‘two’ and perform SET and Merge Operation on them.
The SET statement is the main tool to read observations from a SAS data set. The basics are so obvious you might not EVEN consider them. Just SET and a data set name and there you go. Through SET statement the dataset gets appended while with merge the two datasets get merged on the basis of ID and extra variables are created if needed. Example below.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2. |
What is a monotonic function and how useful is it? |
||||||||||||||||||||||||||||
|
Answer» OUTPUT of the code
|
|||||||||||||||||||||||||||||
| 3. |
What is intnx function and how powerful it is? |
||||||||||||||||||
Answer»
|
|||||||||||||||||||
| 4. |
What is reverse function in sas? |
||||||||||||||||||
|
Answer» In this CODE, we are trying to show the CHARACTERISTICS of ‘do while’ loop. For each iteration, it’s INCREASING the COUNTER and writing in the output DATASET. Please refer the output table below -
|
|||||||||||||||||||
| 5. |
How to count missing value in SAS? |
|
Answer» We can clear the libref through one of the below approaches:-
We can use the below syntax to disassociate a specific library Syntax : LIBNAME libref <CLEAR> Example : Libname temp_lib clear where temp_lib is the libref that you WANT to deassign If, we would like to disassociate all the libref that we have declared in a SAS Session, then use the below-modified version LIBNAME _ALL_ <CLEAR> Example: Libname _ALL_ clear
We can use the LIBNAME function to deassign a library reference. In case, a warning or an error occurs then a message is written to the SAS log. %if (%sysfunc(libname(temp_lib))) %then %put %sysfunc(sysmsg());where temp_lib is the libref that you want to deassign. Note:- In both the above approaches libref is cleared if and only if there are no open files that are ASSOCIATED from that libref.
On the Explorer window go to libraries. Right click on the library that you want to design and select delete. Once you click on Delete you will receive a Delete confirmation with the text "Are you sure you want to remove the library reference NAMED temp_lib?". Once you click Ok, the same is going to get DELETED. |
|
| 6. |
What is N function in sas? |
||||||||||||||||||||||||||||
Answer»
|
|||||||||||||||||||||||||||||
| 7. |
How to concatenate multiple variables in a single variable through SAS? |
||||||||||||
|
Answer» This code is only an illustration to CREATE a table declares variables name, age, and dob with formats and TAKING values USING datalines. input name$ age dob date9.; this statement basically creating variables and GIVING format to dob as date9.
|
|||||||||||||
| 8. |
How to create a numeric date if month Year and day is given through SAS? |
||||||||||||||||||||||||
|
Answer» Here in this CODE we have A (Amount) = 100000 and I (interest) = 0.0925. We need to find Amount and updated interest till five years also the interest INCREASES by 10% every year.
|
|||||||||||||||||||||||||
| 9. |
Write a macro that shows the use of symget in an if condition. |
|||||||||||||||
|
Answer» In this code, we are giving a data or you can say creating a table USING ‘datalines’ but printing the ROWS which only have status as ‘PT’. We have used LOOP here to CHECK each row and thus printing the desired results.
|
||||||||||||||||
| 10. |
What are the different ways to handle a case in sas? |
|
Answer» DATA a;
input name $ 1. marks;
CARDS;
a 100
B 200
c 300
;
run;
procmeansdata = a summean;
run; Output |
|
| 11. |
How to reverse a particular text in sas? |
|
Answer» Because of Cartesian PRODUCT - Cartesian product result-set CONTAINS the number of rows in the FIRST table, MULTIPLIED by the number of rows in the second table. |
|
| 12. |
Write a macro that compares the creation date of all the datasets in two libraries and report in RTF format the libname, dataset name, created date and action for a user for both libraries the sasuser and the work? |
|
Answer» The MONOTONIC function is quite similar to the INTERNAL variable _N_ in the DATA STEP. We can use it to select the records according to their row number. For example, we choose the SSNs from the 501st LINE to the 888th line in the SSN dataset. proc sql;select * from ssn_data where monotonic() between 501 and 800 ; quit;you can also the monotonic() to subset the dataset in the where clause to limit the number of records read/outputted to the FINAL dataset… view source print? proc sql; create table class2 as select monotonic() as rowno, * from sashelp.class where 10 le monotonic() le 20; quit; |
|
| 13. |
How to connect database? |
|
Answer» The INTNX function increments day, year or month specified a date by the parameters given. It is a very helpful function present in sas. Few examples below can SHOW you how - Here it increments the date by 6 weeks, means date after 6 weeks including current week. data _null_; x=intnx('week', '23mar2012'd, 2); put x date9.; run; OUTPUT - 01APR2012 The intnx function increments the day, year or month on the specified date, you can use put as well; data amit; x='13oct1981'd; z=put(intnx('month',x,3,'e'),date9.); run; proc PRINT data=amit; run;output - OBS x z 1 7956 31JAN1982 The intnx function increments the day, year or month on the specified date, you can use the same argument for INCREMENTING 1 month from the date; data amit; x='13oct1981'd; z=put(intnx('month',x,1,'same'),date9.); put z=; run; Output - z=13NOV1981 |
|
| 14. |
How agecat classifications created? |
|
Answer» The REVERSE FUNCTION just reverse the STRING, if there are leading BLANKS they become trailing. data a; x='abcdef'; CHANGE=reverse(x); put change; run;Output – fedcba |
|
| 15. |
How will clean the data having multiple delimited values of a variable in SAS like if data values are “ab,c,*&%$ ~d” and you want to make it like “abcd”? |
|
Answer» we can count missing value in SAS USING NMISS function. For example – data a; x1=2; x2=3; x3=.; nvars_miss=nmiss(of x1-x3); put nvars_miss=; run; PROC PRINT data = a; run; |
|
| 16. |
What is the difference between calculating the 'mean' using the mean function and PROC MEANS? |
|
Answer» The N function counts the number of non-missing values in a row DATA a; x1=2; X2=3; x3=4; nvars_nonmiss=n(of x1-x3); put nvars_nonmiss=; RUN; proc print data = a; run;Output – OBS x1 x2 x3 nvars_nonmiss 1 2 3 4 3 |
|
| 17. |
For what purpose would you use the RETAIN statement? |
|
Answer» we can use CATX function for it. CATX function with a SERIES, Let’s say you want to concatenate the value of a VARIABLE; data a; sp='|'; x1='a'; x2='b'; x3='c'; STRING=catx(sp,of x1-x3); run; proc print data=a; run;output – Obs sp x1 x2 x3 string 1 | a b c a|b|c |
|
| 18. |
What is PAD option and how it is used? |
|
Answer» The mdy function creates a numeric date from the VALUES of the month DAY and year. data date_data; input name $ month year day; datalines; ram 10 1981 13 GEETA 04 1982 20 ; run; data date_date1; set date_data; attrib bdy format=date9.; bdy=mdy(month,day,year); run; proc print data= date_date1; run;Output – Obs name month year day bdy 1 ram 10 1981 13 13OCT1981 2 geeta 4 1982 20 20APR1982 |
|
| 19. |
What will be the output of the code below? |
|
Answer» Let suppose we have a table admit in sasuser library and we have to fetch the student who has age GREATER than the average age then this can be code like the one below using symget. %macro ch; proc sql; SELECT AVG(age) into:avg_age from sasuser.admit; quit; data x; set sasuser.admit; ageif=symget('avg_age'); if age gt ageif; run; %mend ch; %ch; |
|
| 20. |
and @? |
|
Answer» In SAS, we can convert text into any case like LOWCASE, UPCASE and PROCASE. LOWCASE – It converts the string into small letters or in lower case. data lower; x='SAS'; y=lowcase(x); x=lowcase('CHAMP'); run; PROC print data=lower; run;output – Obs x y 1 champ sasUPCASE – It converts the string into CAPITAL letters or in UPPER case. data uper; x='sAs'; y=upcase(x); x=upcase('ChaMP'); run; proc print data=uper; run;output – Obs x y 1 CHAMP SASPROCASE – It converts the string into proper letters or in other words we can say the FIRST letter upper/upcase and rest in lowercase. Example- data procase; x='sAs'; y=procase(x); x=procase('ChaMP'); run; proc print data=procase; run;output – Obs x y 1 Champ Sas |
|
| 21. |
what is the difference between |
|
Answer» The tranwrd function helps in the replacement of a string in a char variable. We can reverse the text/values in SAS using tranward function. It has many functions LIKE reversing, REPLACING ETC. For example – Converting the multiple occurence of a string; data x; input name$; datalines; highhigh high cc ; run; data a; set x; name=tranwrd(name,'high','hi'); run; proc PRINT data=a; run;output – Obs name 1 hihi 2 hi 3 cc |
|
| 22. |
How does SAS Processing done explain briefly? |
|
Answer» The options nofmterr mprint mlogic symbolgen; %macro datecompare; proc format; value $bckcolor 'Dates match No action'='green' 'PLZ CHECK'=red; RUN; %macro a; %do i=1 %to 5; data SASUSER.a&i; set sasuser.admit; run; proc copy in =sasuser out=work memtype=data; select a&i; run; %end; %mend a; %a; proc sql noprint; select count(distinct memname) into:cntwork from dictionary.columns where upcase(libname) ='WORK'; quit; %put &cntwork; proc sql noprint; select count(distinct memname) into: cntuser from dictionary.columns where upcase(libname) ='SASUSER' and upcase(memname) in ('A1','A2','A3','A4','A5'); quit; %put &cntuser; proc sql; create table wrk as select libname,memname,crdate from dictionary.tables where upcase(libname) ='WORK' and upcase(memname) in ('A1','A2','A3','A4','A5'); quit; proc sql; create table suser as select libname,memname,crdate from dictionary.tables where upcase(libname) ='SASUSER' and upcase(memname) in ('A1','A2','A3','A4','A5'); quit; proc sort data=wrk (rename=(crdate=crdate1 libname=libname1)); by memname; run; proc sort data=suser; by memname; run; data final; merge wrk(in=a) suser(in=b); by memname; if a and b; run; data new; set final; if LEFT(TRIM(crdate))=left(trim(crdate1)) then action='Dates match No action'; else action='PLZ CHECK'; run; proc sql; create table new as select memname,libname,crdate,libname1,crdate1,action from new; quit; ods listing close; ods rtf file='\\path \new.rtf'; proc report data=new nowd headline headskip split='*'; Title1 j = center font = arial h = 4 color = blue "Creation Date comparision for"; Title2 j = center font = arial h = 4 color = blue "DATASETS of library sasuser and work"; columns memname libname crdate libname1 crdate1 action; define memname/display width=9 spacing=3 center; define libname/display width=2 spacing=3 center; define crdate/display width=2 spacing=3 center; define libname1/display width=3 spacing=3 center; define crdate1/display width=9 spacing=3 center; define action/display width=9 spacing=3 center style ={background =$bckcolor.};; run; ods rtf close; ods listing; %mend datecompare; %datecompare; |
|
| 23. |
What is Macro and how it can be used? |
|
Answer» Procsql;
Connect to Teradata( USER= “ &user_id.” PASSWORD =” &dbpass”
tdpid =rchgrp2 MODE= ‘teardata’); CREATE table work. Account_details as (SELECT Account_ Number, Enroll_ Date, Sales , City From Master_ acct_ details Where Account_ Number is not null and Sales GT 40000); Disconnect from Teradata; QUIT; |
|
| 24. |
What is PAD option and how it is used? |
|
Answer» Numeric Format AG’ is created, in the work LIBRARY (is a temporary format) with the specified RANGES: Proc format lib=work; Value ag 0-<30=’young’ 30-<61=’old’; Run; Proc print data=sasuser.admit; Format age ag.; |
|
| 25. |
HeightWeightMaxval69112.511370848489.5789065.397.59857.38888 |
|
Answer» In case you want to delete multiple delimiters in one GO, you NEED to put all delimiters in the second ARGUMENT in any order and use the SAS function compress. data clean; x='AB,c,*&%$ ~d'; y=compress(x,'~$%&* ,'); run; proc print data=clean; run;Output – OBS x y 1 ab,c,*&%$ ~d abcd |
|
| 26. |
Output |
|
Answer» The mean() function is used to calculate the mean of one observation across the variable. It is used to generate a horizontal DATA summary. DATA A; INPUT NAME$ SUBJ1 SUBJ2 SUBJ3; CARDS; A 95 96 99 B 85 90 70 C 60 70 80 ; RUN; DATA B; SET A; MEAN = MEAN(SUBJ1,SUBJ2,SUBJ3); RUN; PROCPRINT; RUN;Proc Means is used to calculate the mean of a variable across all observations. It is used for generating the vertical data summary (i.e. mode of operation is column-wise). By default, it calculates N, Mean, Std DEV, Minimum, Maximum statistics. |
|
| 27. |
HeightWeight69112.5708489.57865.397.557.388 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Answer» RETAIN statement causes a variable that is defined during the input statement to be retained across data set iterations, in other words, retain statement retains the variable value at each iteration and keeps on substituting it, the pdv does not get cleared when you use the retain statement, LET’s try to understand the basic example explained below – Table - mylib.clinical
Suppose we have the above clinical table in the form of SAS Dataset in lib – ‘mylib’. CONSIDERING the fact the following code will give the DESIRED results. Data Clinical_Analysis; Set mylib.clinical; If '01JAN2018'D <= Date <= '31MAR2019'D ; array diag(*) $diag1 - diag5; do i=1 to 5; if diag(i) in ('D45') then f_diag =1; END; run; proc sort data = Clinical_Analysis; by IDs date; run; Data diag_pat (keep = IDs YOB Date f_diag first_date diag age); set Clinical_Analysis; by Ids; format first_date date9.;retain diag first_date age; /*retaining diag first_date and age at every iteration */ if first. Ids then do; diag=0; first_date =date; age =0; end; age = Year(first_date) - yob; if f_diag =1 then diag=1; if last.Ids; run; Proc freq data = diag_pat; title "All required counts"; tables diag age/missing list; run;output: Dataset of the code – Table: diag_pat
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28. |
Fetch 3 variables: height, weight, maxval(max of height or weight) with format=3.Dataset |
|
Answer» The PAD OPTION can be used to read the source DATA having the variable length records, so to read the variable length of records we can use the PAD option, the PAD option can be used with the infile statement; example data TEST; infile 'C:\Users\Anshu\Desktop\test.txt' PAD; input @1name $6. @10 SEX $1. @12 marks 3. @14 salary 8.; run; PROC print data=Test; run; |
|
| 29. |
RnoNameMarksRank2B4911A5023C5134D5245E524 |
||||||||||||
|
Answer» DATA Test;
INPUT @1name $7. @9 SEX $1. @10 marks;
cards;
Anshukr M123
MohitaS F32
;
run;
proc PRINT data=test;
run; Answer
|
|||||||||||||
| 30. |
Output |
||||||||||||||||||||||||||||||||
|
Answer» The use of double TRAILING is that, if you have datalines in one line then you can use ; data TEST1; input name $ age marks ; datalines; am 12 95 ra 13 67 pa 14 98 sa 14 87 ; run; proc print data=test1; run;Output
The use of SINGLE @ is in the holding the line, it basically is used in more than one input statement, the pointer basically hold the line after reading the values, it basically holds the value and checks the condition; data test2; input @1 gender $1. @; if gender ne 'F' then delete; input @3 age @5 marks; datalines; F 13 56 M 12 78 F 13 78 M 56 90 ; run; proc print data=test2; run;Output
|
|||||||||||||||||||||||||||||||||
| 31. |
RnoNameMarks1A502B493C514D525E52 |
|
Answer» The SAS processing is in two steps
|
|
| 32. |
Dataset |
|
Answer» Macro is way of automating in sas programs. There are MANY ways to create macro. %macro get_var_dist (data_nm , categ_cut_off); /* Taking list of variables in the dataset along with type*/ proc contents data=&data_nm. out=_content_; run; /* NOTE - how data_nm is getting resolved. */ /* Fiding number of variables to define loop */ proc sql noprint; select count(*) into: nvars from _content_; quit; /* Note this is another way of DEFINING macro variables */ %put "No of Variables is " &nvars. ; /* Note this can be a useful way to detect the value of macro variables.*/ %do i=1 %to &nvars. ; data _null_; set _content_; if _n_ = &i. then do; call symput("variable", name); call symput("var_type",type); end; run; /* Note - 1: One more way of defining variables. Please note here information is being passed from general SAS dataset to SAS macros using call symput 2: Please see how to run do a loop */ %put "Variable is " &variable. ; %put "Variable Type is " &var_type. ; proc sql noprint; select count(distinct &variable) into: distinct_categories from &data_nm.; quit; %put "Number of distinct categories is &distinct_categories." ; /* Note the syntax of writing if else condition */ /* %do .... %end; defines the block */ /* Missing command below includes missing value as a category */ /* Also note, if you don't use %eval it can throw errors */ /* if comparison involves floating numbers, you will need to use %sasevalf */ %if %eval(&distinct_categories.) <= %eval(&categ_cut_off.) %then %do; Title "Freq Dist for Variable &variable. as number of distinct category is &distinct_categories."; proc freq data=&data_nm. ; table &variable. / missing ; run; %end; %if %eval(&var_type.) = 1 %then %do; Title "Univariate Dist for Variable = &variable. "; proc univariate data=&data_nm. PLOT; var &variable. ; run; %end; %end; %mend get_var_dist; options symbolgen mlogic mprint; %get_var_dist(data_nm=sashelp.heart, categ_cut_off=25); %get_var_dist(data_nm=sashelp.asscmgr, categ_cut_off=10); |
|
| 33. |
Calculate the rank according to the marks in ascending order and if any marks value is repeated the rank should be the same for both. |
|
Answer» The PAD OPTION can be used to READ the source data having the variable length RECORDS, so to read the variable length of records we can USE the PAD option, the PAD option can be used with the infile statement; example data Test; infile 'C:\Users\Anshu\Desktop\test.txt' PAD; input @1name $6. @10 sex $1. @12 marks 3. @14 salary 8.; run; proc print data=Test; run; |
|
| 34. |
Write code to connect the Teradata. |
| Answer» data test; INPUT name$ WEIGHT; CARDS; a 25 b 30 c 35 d 40 ; run; proc SQL; select name, weight from test union all select 'Total', sum(weight) from test; quit; | |
| 35. |
What are the different ways to create a table in proc SQL? |
| Answer» DATA test; input id sal; cards; 1 300 1 200 3 900 2 300 2 400 3 700 2 100 3 800 ; run; PROC sort data =test out=test1; by id sal; run; proc sql; CREATE table test2(drop=number) as select *, monotonic() as number from test1 GROUP by id having number=max(number); quit; | |
| 36. |
What is the difference between UNION and UNIONALL Operator in SAS? |
|
Answer» CONNECTING to teradata using pass through Procsql; Connect to Teradata( USER= “ &user_id.” PASSWORD =” &dbpass” tdpid =rchgrp2 MODE= ‘teardata’); CREATE table work. Account_details as(SELECT Account_ Number, Enroll_ Date, Sales, City From Master_ acct_ details Where Account_ Number is not null and Sales gt 40000 ); Disconnect from Teradata; Quit; Connecting to db2 using pass through: Procsql; Connect to db2( DATABASE=CRD_ PROD USER= “ &user_id.” PASSWORD=” &dbpass”); Create table work. Account_details as(Select Account_ Number, Enroll_ Date, Sales, City From Master_ acct_ details Where Account_ Number is not null and Sales gt 40000 ); Disconnect from db2; Quit;Other way using the library assignments: Libname AM DB2 DATABASE= CARD_USA Schema=DDKAUTO USER=”&user_ id.” PASSWORD= “&dbpass”; Procsql;Create table work. Account_details as(Select Account_ Number, Enroll_ Date, Sales, City From AM.Master_ acct_ details Where Account_ Number is not null and Sales gt 40000); |
|
| 37. |
How can we create an index? |
|
Answer» There are multiple ways for creating table in PROC sql I. Create Table From Column Definition We can create a NEW table without rows by using the CREATE TABLE statement to define the columns and attributes. We can specify a column’s NAME, type, length, informat, format and label. procsql; createtable employee( ssn CHAR(9), dob numformat = DATE9.informat = DATE9.label = "Date Of Birth", doh numformat = DATE9.informat = DATE9.label = "Date Of Hire", GENDER char(1) label = "Gender", estat char(10) label = "Employement Status"); insertinto employee values ("111111111",500,25000,"M","ACTIVE"); quit; procsql; select * from employee; quit;II. Create Table from a Query Result Many times, there are situations wherein we already have a structure of the table/view and we are trying to create a mirror table that is referring to columns of the earlier existing table. In such cases, we can use the same CREATE TABLE Statement and place it before the SELECT Statement. An additional benefit of using this approach of creating the table is that the data of the new table is derived on the basis of existing data from the parent table. procsql; createtable employee1 as select * from employee quit; procsql; select * from employee1; quit;III. Create Table Like an Existing Table To create an empty table that has the same columns and attributes as an existing table, we use the LIKE clause while creating the table. One point to note is that an empty table is created using this method and no data is populated inside the table. procsql;createtable employee3 like employee; quit; |
|
| 38. |
OBSIDsYOBDatediag1daig2daig3daig4daig511002-Mar-862-Mar-18D4500D45021002-Mar-865-Mar-180D4500D4531002-Mar-868-Mar-180C500C50D4541015-Jan-808-Jan-1800D45D45051015-Jan-802-Feb-18D4500D45061015-Jan-8027-Feb-180D4500D4571015-Jan-8024-Mar-18D450D450081015-Jan-8018-Apr-18D4500D45091024-Jan-8518-Jan-170D4500D45101024-Jan-8525-Jan-18D4500D450111024-Jan-851-Feb-180D4500D45121024-Jan-858-Jan-1800D45D450131024-Jan-8515-Feb-1900D45D4501410316-Jan-9015-Feb-180D4500D451510316-Jan-9025-Feb-18D4500D4501610316-Jan-907-Mar-180D4500D451710316-Jan-9017-Mar-1800D45D4501810425-Jan-9227-Feb-1800D45D4501910425-Jan-9224-Mar-180D4500D452010425-Jan-9218-Apr-18D4500D450 |
|
Answer» Information From Dataset: A Information From Dataset: B The output of the UNION Operator UNION Operator is used to club the specific variable information from both the tables. Apart from updating the information, it also removes the duplicate data and SORTS the combined information. The output of UNIONALL Operator UNIONALL Operator works by appending the information from dataset B after the information from dataset A. It doesn’t remove the duplicates or sorts the resultant data. Note: If the VARIABLES are EXISTING in both the tables, but the order of the same is different. SAS throws the below error –
|
|
| 39. |
Table Name – Clinical |
|
Answer» Format for creating a simple index - Data <dataset_name> (INDEX = (<variable-name></UNIQUE></NOMISS>)) Creating a single index in one go Example : data a(index=(seq /unique /nomiss)); Set a; RUN; Creating multiple indexes in one go Example: data a(index =(seq /unique /nomiss State /unique YEAR /unique /nomiss) Set a; Run; Format for creating a COMPOSITE index- Data <dataset_name> (INDEX = (index-name = <var1 var2 etc></UNIQUE></NOMISS>)) Creating a composite index – Example – data a(index=(quarter_month = (quarter month) /nomiss) Set a; Run;Note: We can also use the proc’s to create the indexes in the newly generated output DATASETS. Additionally, we COULD also use the proc datasets procedure and proc SQL to generate indexes. |
|
| 40. |
Find the number of patients with daig code (D45) and calculate the age of each patient between 01st Jan 2018 to 31 March 2019 from the table given below. |
||||||||||||||||||||||||||||||||||||||||||||||||
|
Answer» SUPPOSE we have the above clinical table in the form of SAS Dataset in lib – ‘mylib’. Considering the fact, the following code will give the desired results. Data Clinical_Analysis; Set mylib.clinical; If '01JAN2018'D <= Data <= '31MAR2019'D ; array DIAG(*) $diag1 - diag5; do i=1 to 5; if diag(i) in ('D45') then f_diag =1; END; run; proc sort data = Clinical_Analysis; by IDS date; run; Data diag_pat (keep = IDs YOB Date f_diag first_date diag age); set Clinical_Analysis; by Ids; format first_date date9.; retain diag first_date age; if first.Ids then do; diag=0; first_date =date; age =0; end; age = Year(first_date) - yob; if f_diag =1 then diag=1; if last.Ids; run; Proc freq data = diag_pat; title "All required COUNTS"; tables diag age/missing list; run;output: Dataset of the code – Table: diag_pat
|
|||||||||||||||||||||||||||||||||||||||||||||||||