This article includes most frequently asked SAS interview questions which would help you to crack SAS Interview with confidence. It covers basic, intermediate and advanced concepts of SAS which outlines topics on reading data into SAS, data manipulation, reporting, SQL queries and SAS Macros. It includes questions ranging from simple theoretical concepts to tricky questions.1. Difference between INPUT and INFILEThe INFILE statement is used to identify an external file while the INPUT statment is used to describe your variables.FILENAME TEST 'C:DEEPFile1.xls';DATA READIN;INFILE TEST;LENGTH NAME $25;INPUT ID NAME$ SEX;RUN; Note: The variable name, followed by $ (dollar sign), idenfities the variable type as character.In the example shown above, ID and SEX are numeric variables and Name a character variable.2. Difference between Informat and FormatInformats read the data while Formats write the data.Informat - To tell SAS that a number should be read in a particular format.For example: the informat mmddyy6.
Tells SAS to read the number121713as the date December 17, 2013.Format - To tell SAS how to print the variables.3. Difference between Missover and TruncoverMissover -When the MISSOVER option is used on the INFILE statement, the INPUT statement does not jump to the next line when reading a short line. Instead, MISSOVER setsvariables to missing.Truncover - It assigns the raw data value to the variable even if the value is shorter than the length that is expected by the INPUT statement.The following is an example of an external file that contains data:This DATA step uses the numeric informat 4. To read a single field in each record of raw data and to assign values to the variable ID.data readin;infile 'external-file' missover;input ID4.;run;proc print data=readin;run;The output is shown below:Obs ID1.2.3.4 4444Truncoverdata readin;infile 'external-file' truncover;input ID4.;run;proc print data=readin;run;The output is shown below:Obs ID1 12 223 3334 44444. Purpose of double trailing@@ in Input Statement?The double trailing sign (@@)tells SAS rather than advancing to a new record, hold the current input record for the execution of the next INPUT statement.DATA Readin;Input Name $ Score @@;cards;Sam 25 David 30 Ram 35Deeps 20 Daniel 47 Pars 84;RUN;The output is shown below:Double Trailing5.
Using SAS Output Delivery System (ODS), you can extract the attributes from a data set without listing the variables. There are different destinations that can be.
11.What is Program Data Vector (PDV)?PDV is a logical area in the memory.How PDV is created?SAS creates a dataset one observation at a time.Input buffer is created at the time of compilation, for holding a record from external file. PDV is created followed by the creation of input buffer.SAS builds dataset in the PDV area of memory.12. What is DATA NULL?The DATA NULL is mainly used to create macro variables. It can also be used to write output without creating a dataset.The idea of 'null' here is that we have a data step that actually doesn't create a data set.13. What is the difference between '+' operator and SUM function?SUM function returns the sum of non-missing arguments whereas “+” operator returns a missing value if any of the arguments are missing.Suppose we have a data set containing three variables - X, Y and Z. They all have missing values.
We wish to compute sum of all the variables.data mydata2;set mydata;a=sum(x,y,z);p=x+y+z;run;The output is shown in the image below:SAS: SUM Function vsPlus OperatorIn the output, value of p is missing for 4th, 5th and 6th observations.14. How to identify and remove unique and duplicate values? Use PROC SORT with NODUPKEY and NODUP Options.2.
Variables -The detailed explanation is shown below:SAMPLE DATA SETIDNameScore1David451David742Sam452Ram543Bane873Mary923Bane874Dane235Jenny875Ken876Simran638Priya72Create this data set in SASdata readin;input ID Name $ Score;cards;1 David 451 David 742 Sam 452 Ram 543 Bane 873 Mary 923 Bane 874 Dane 235 Jenny 875 Ken 876 Simran 638 Priya 72;run;There are several ways to identify and remove unique and duplicate values:PROC SORTIn PROC SORT, there are two options by which we can remove duplicates.1. NODUPKEY Option 2.
This list of Q&A is really comprehensive! I spent a day and currently stopped Q26, and will continue to finish the rest tomorrow. I have watched SAS official tutorials but none of those are as helpful as the questions in this blog.
I would recommend newbies, like myself, spend extra time to expand a little bit beside the scope of each question, and don't just look for answers for questions, instead treat each question seriously and key in the codes in SAS to see how the answer works. By practicing along the way, I have developed a pretty good sense of the data structure and common syntaxes. Good luck everyone!
Hi,This is satish.Please find the solution.data EMPCURR;input empid currency$20.;CUURCOUNTDEL=LENGTH(currency)-length(compress(currency,','));call symput('xc',max(CUURCOUNTDEL)+1);cards;1234 USD1289 USD1389 INR1456 INR,USD1567 USD,GBP,INR1897 USD,INR,AFN,DZD,ABC;%put &xc;data EMPCURR1 (drop=i currency);set EMPCURR;array scan(&xc.) $;do i= 1 to &xc.;scan(i)=scan(currency,i,',');end;run;data EMPCURR2(keep=empid currency);set EMPCURR1;array scan(&xc.) $;do i= 1 to &xc.;if scan(i) ne ' ' then currency=scan(i);output;end;run;proc sort data=EMPCURR2 nodup;by empid;run.