BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JUDE2
Calcite | Level 5

Hello.
I'm practicing because it's a test in December. Sadly I don't understand exercise number 2.
Please explain why there are 117 columns.
I keep getting 25.
(Just in case, I ran the answer as it is, but it still comes out as 25.)

-----------------------------------------------------------------------------------

Answer: 117

proc
sort data=cert.input08a out=work.input08a;
  by ID;
run;

proc sort data=cert.input08b out=work.input08b;
  by ID;
run;

data results.match08 results.nomatch08 (drop=ex: );
  merge work.input08a (in=a) work.input08b (in=b);
  by ID;
  if a and b then output results.match08;
  else output results.nomatch08;
run;

proc contents data=results.match08;
run;

proc contents data=results.nomatch08;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  I'm not sure how you derived your estimate, but the SAS log shows you the exact answer. It looks like you're doing the Practice Exam for the Base Programming Using SAS 9.4 Performance-Based Exam. The datasets you are using are CERT.INPUT08a and CERT.INPUT08b.
If you run a PROC CONTENTS on each file BEFORE you run your code, you should see THIS:

Cynthia_sas_0-1733768387117.png

Assuming that there's a one-to-one match for most of the rows based on ID, just looking at those numbers, I would expect to see at least 2 non-matches. The question asked you to merge the 2 input files BY ID, so without looking at the data, the only way to verify the mismatches and matches is to either manually go through the 2 files row by row or look in the SAS log.

Cynthia_sas_1-1733768548013.png

Here's the original setup and the 4 questions you have to answer. There are 2 NOTES in the log that answer all 4 questions. I'm not sure why you can't see the SAS Log. All you have to do is run the code. If you are practicing the exam using our copy of the exam, we have a lab where the data is already pre-loaded, so all you have to do is establish your LIBNAME statements to be able to access the data and run code. We use SAS Studio in the Lab for the exam, so you should be able to see  the log for the code and for the final PROC CONTENTS.

  Keep in mind that when you answer the questions, you've got to pay attention to which results file is being asked about MATCH08 or NOMATCH08 and you've got to pay attention whether you're asked to provide the number of observations OR rows; or whether you're asked to provide the number of variables OR columns. My guess is that you're expecting to see 117 variables in both RESULTS.MATCH08 and RESULTS.NOMATCH08; however, remember that you have the DROP= option for RESULTS.NOMATCH08 in the DATA statement for the MERGE. So this means that the ONLY variables left in RESULTS.NOMATCH08 are as shown below:

Cynthia_sas_2-1733769258261.png

  The form of the DROP= option has you excluding ALL the variables that start with "ex" and if you look at the PROC CONTENTS from before you do the merge you'll see that there are a LOT of variables that start with "ex".

 

Cynthia

 

View solution in original post

9 REPLIES 9
Tom
Super User Tom
Super User

How many variables are in a dataset will be displayed in the SAS log when you run the program.

12   data x;
13    set sashelp.class;
14    run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.X has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

The only way you would get a different number of variables than expected would be if the input dataset had a different number of variables.

 

Perhaps they have tricked you by running a data step that writes TWO datasets?  

15   data x y(drop=age);
16    set sashelp.class;
17    run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.X has 19 observations and 5 variables.
NOTE: The data set WORK.Y has 19 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds

Are you looking at the number of variables in the wrong one of the two datasets? (or perhaps the question has a typo and asked you to look at the wrong dataset?

JUDE2
Calcite | Level 5

Thank you for your quick response!
If I write the answer to the question, it's frustrating that I can't see the log record. 😞


The current estimate is inputA + inputB-1, so I think it's 93+25-1 = 117. 😞

Tom
Super User Tom
Super User

@JUDE2 wrote:

Thank you for your quick response!
If I write the answer to the question, it's frustrating that I can't see the log record. 😞


The current estimate is inputA + inputB-1, so I think it's 93+25-1 = 117. 😞


That would only be true if there was only one variable in common between the two datasets.

In general if you merge two datasets:

merge A B;

The number of variables is the superset of all distinct variable names from the two datasets.  So the number of variables that only appear in A plus the number of variables that only appear in B plus the number of variable that appear in both.

 

The added issue in the data step you showed is that one of the output dataset was excluding all of the variables whose name started with EX.  So if that is the dataset they want the variable count for you need to reduce the count by the number of variables that started with those letters.

 

Also don't get confused and tell them how many OBSERVATIONS will be created.  The dataset SASHELP.CLASS has 19 observations and only 5 variables.

Cynthia_sas
SAS Super FREQ

Hi:

  I'm not sure how you derived your estimate, but the SAS log shows you the exact answer. It looks like you're doing the Practice Exam for the Base Programming Using SAS 9.4 Performance-Based Exam. The datasets you are using are CERT.INPUT08a and CERT.INPUT08b.
If you run a PROC CONTENTS on each file BEFORE you run your code, you should see THIS:

Cynthia_sas_0-1733768387117.png

Assuming that there's a one-to-one match for most of the rows based on ID, just looking at those numbers, I would expect to see at least 2 non-matches. The question asked you to merge the 2 input files BY ID, so without looking at the data, the only way to verify the mismatches and matches is to either manually go through the 2 files row by row or look in the SAS log.

Cynthia_sas_1-1733768548013.png

Here's the original setup and the 4 questions you have to answer. There are 2 NOTES in the log that answer all 4 questions. I'm not sure why you can't see the SAS Log. All you have to do is run the code. If you are practicing the exam using our copy of the exam, we have a lab where the data is already pre-loaded, so all you have to do is establish your LIBNAME statements to be able to access the data and run code. We use SAS Studio in the Lab for the exam, so you should be able to see  the log for the code and for the final PROC CONTENTS.

  Keep in mind that when you answer the questions, you've got to pay attention to which results file is being asked about MATCH08 or NOMATCH08 and you've got to pay attention whether you're asked to provide the number of observations OR rows; or whether you're asked to provide the number of variables OR columns. My guess is that you're expecting to see 117 variables in both RESULTS.MATCH08 and RESULTS.NOMATCH08; however, remember that you have the DROP= option for RESULTS.NOMATCH08 in the DATA statement for the MERGE. So this means that the ONLY variables left in RESULTS.NOMATCH08 are as shown below:

Cynthia_sas_2-1733769258261.png

  The form of the DROP= option has you excluding ALL the variables that start with "ex" and if you look at the PROC CONTENTS from before you do the merge you'll see that there are a LOT of variables that start with "ex".

 

Cynthia

 

JUDE2
Calcite | Level 5

Thank you!!
It's been a great help!!

Tom
Super User Tom
Super User

@JUDE2 wrote:

If I write the answer to the question, it's frustrating that I can't see the log record. 😞

This sounds like you are having trouble with switching between the window where the SAS code is running and the window where the TEST is asking you the questions?

 

Perhaps someone with more experience on how to take these particular tests could help you with some concrete ideas on how to make that easier.

 

I would assume that you are using a browser to do both.  SAS/Studio to run the SAS code in one TAB and another TAB where the test questions are being presented and the answers are entered.  Personally in that type of situation I like to open them in two different windows of the browser (or perhaps use two different browsers if necessary, say CHROME for one and EDGE or SAFARI for the other.)  Then I can toggle more easily between the two.  Personally I like to use key stroke ALT-TAB for this.

 

If you are forced to use two tabs in the same browser then make sure you don't have too many other tabs open so it is easier see which tab is which and switch between them.

ballardw
Super User

I would suggest redoing the instructions at the start to create the data sets if none of the other posts helped. You may have done something that removed variables in a previous exercise by accident.

JUDE2
Calcite | Level 5

Thank you for your answer.
However, what I posted itself is the answer to the exercise question posted by SAS.
I don't know SAS well, so I'm looking at the correct answer and estimating it to be the opposite, but it's frustrating that it's not working at the moment. 😞

ballardw
Super User

HINT: Show us the LOG from running the code in the original question. And the results of the proc contents.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1206 views
  • 0 likes
  • 4 in conversation