If you are given an unsorted data set, how will you read the last observation to a new dataset?

We can read the last observation to a new dataset using end = dataset option. For example: data example.newdataset; set example.olddataset end=last; If last; run; Where newdataset is a new data set to be created and olddataset is the existing data set. last is the temporary variable (initialized to 0) which is set to 1 … Read more

How does PROC SQL work?

PROC SQL is nothing but a simultaneous process for all the observations. The following steps occur when a PROC SQL gets executed: SAS scans each and every statement in the SQL procedure and checks the syntax errors. The SQL optimizer scans the query inside the statement. So, the SQL optimizer basically decides how the SQL … Read more

What would be the result of the following SAS function (given that 31 Dec 2017 is Saturday)? Weeks = intck (‘week’,’31 dec 2017’d,’01jan2018’d); Years = intck (‘year’,’31 dec 2017’d,’01jan2018’d); Months = intck (‘month’,’31 dec 2017’d,’01jan2018’d);

Here, we will calculate the weeks between 31st December 2017 and 1st January 2018. 31st December 2017 was a Saturday. So 1st January 2018 will be a Sunday in the next week. Hence, Weeks = 1 since both the days are in different weeks. Years = 1 since both the days are in different calendar … Read more

What is the purpose of trailing @ and @@? How do you use them?

The trailing @ is commonly known as the column pointer. So, when we use the trailing @, in the Input statement, it gives you the ability to read a part of the raw data line, test it and decide how can the additional data be read from the same record. The single trailing @ tells … Read more

Can you tell the difference between VAR X1 – X3 and VAR X1 — X3?

When you specify sing dash between the variables, then that specifies consecutively numbered variables. Similarly, if you specify the Double Dash between the variables, then that would specify all the variables available within the dataset. For Example: Consider the following data set: Data Set: ID NAME X1 X2 Y1 X3 Then, X1 – X3 would … Read more