The following the problem from the free model test paper of Base SAS certification exam and the code I wrote.The answer I get is not tallying with the right answer given:
This project will use data set cert.input27. At any time, you may save your program as program27 in cert\programs. You will use this program in the next project.
Write a SAS program that will:
o Create output data set results.output27a as a subset of cert.input27 where the country variable's value is "US" (any variation of case, such as US or us).
o Sort results.output27a:
first by the variable state in ascending order
then by Postal_Code in descending order
and finally by employee_ID in ascending order.
Run the program and use the results to answer the question below.
1.What is the value of Employee_ID for observation 100 in results.output27a?
Right Answer given is : 120781 My answer is 121030. I checked for the employee_id 120781. It is not there in the input27 dataset.
can you kindly explain.
The code I wrote :
Proc sort data = cert.input27 out= output27;
by state descending postal_code employee_id;
proc print data=output27 (firstobs=100 obs=100);
Without the original Cert.Input27 can't say.
Could be a number of things: Different input data, different version of an answer key for the data provided, typo, some where you modified the Cert.Input27 data set prior to this exercise. Do you have version information for this practice and the key?
Did you check to see if any of the State values have different case?
Can I send you the input dataset? No all the observations had upper case observations in the country variable.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
From the code you show the only other concern the Country variable might have is leading spaces.
I asked about whether the State variable might also have separate case because it is used in the Proc Sort code (I am assuming the other variables were numeric in the sort By statement). If a State has values like "AK" "Ak" and "ak" the sort on state could have a different than expected sort order.
Version of the documents and data is important because if the answer key is for one version and the data you are using is from a different one than I would expect differences. Also, someone here may recognize that there was a problem with a specific release.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.