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

Create a data set consisting only of the Dinosaur BBQ locations in the state of New

York. Print and present your properly titled table.

 

 
Proc sort data= Bbq;
By State New York;
Run;
 
Does this look right or am I missing something? It's saying it does not recognize New York as a variable but I am not sure what else to use to get the right results. 
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@harveysarah0 wrote:

So I realized it's NY and not New York.

 

PROC print data= Bbq (where=(state='NY'))
By State;
Run;

 

Would this be correct?


You can try it and find out yourself. I don't know if it is correct because I don't have your data set.

--
Paige Miller

View solution in original post

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

spaces are not allowed in variable names in SAS. I suspect that 'New York' is a label. 

 

Run the code below and check the actual variable name and use that instead.

 

proc contents data=Bbq;
run;
harveysarah0
Calcite | Level 5

The actual variable name is State. But I would like just a table with New York so what would I need to add?

PeterClemmensen
Tourmaline | Level 20

Ah ok. Then @PaigeMillers code is the way to go.

PaigeMiller
Diamond | Level 26

Perhaps this is what you want:

 

Proc sort data= Bbq(where=(state='New York')) out=bbq1;
By State;
Run;

 

Learning tip: 

You need to understand the difference between a SAS variable in a data set (in this case the variable is STATE) and the value of the variable (in this case the value of the variable is 'New York'). These two things should not be confused. The BY statement wants the name of the variable (in this case STATE). The WHERE clause tells the PROC which values of STATE (in this case 'New York') are to be used by the procedure.


I have added the output data set BBQ1, as this is a good programming practice, which does not overwrite your original BBQ data set.

 

But going back to the original problem statement:

 

Create a data set consisting only of the Dinosaur BBQ locations in the state of New

York. Print and present your properly titled table.

 

It's not clear why you need PROC SORT here for this as no sorting was requested. PROC PRINT seems like all you need.

--
Paige Miller
harveysarah0
Calcite | Level 5

Thanks for your help. Why does this error come up when I try what you have?

 

NOTE: Input data set is already sorted, no sorting done.
NOTE: There were 0 observations read from the data set WORK.BBQ.
WHERE 0 /* an obviously FALSE WHERE clause */ ;
NOTE: The data set WORK.BBQ has 0 observations and 4 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.15 seconds
cpu time 0.07 second

 

PaigeMiller
Diamond | Level 26

So we can't know what you did, unless you show us the ENTIRE log, not just the error messages.

 

Please help us by formatting the log properly. When you copy the log, please click on the {i} icon and paste the log into the window that appears. This will make the log readable. PLEASE DO NOT SKIP THIS STEP.

--
Paige Miller
harveysarah0
Calcite | Level 5

PROC PRINT data= Bbq (where=(state='New York'));
By State;
Run;

PaigeMiller
Diamond | Level 26

This is not the LOG. Please follow my instructions when you provide the entire LOG for this code.

--
Paige Miller
harveysarah0
Calcite | Level 5

69 PROC PRINT data= Bbq (where=(state='New York'));
70 By State;
71 Run;

NOTE: No observations in data set WORK.BBQ.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds


72 Proc print data= Bbq(where=(state='New York')) out=bbq1;
---
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, BLANKLINE, CONTENTS, DATA, DOUBLE,
GRANDTOTAL_LABEL, GRANDTOT_LABEL, GRAND_LABEL, GTOTAL_LABEL, GTOT_LABEL, HEADING,
LABEL, N, NOOBS, NOSUMLABEL, OBS, ROUND, ROWS, SPLIT, STYLE, SUMLABEL, UNIFORM, WIDTH.
ERROR 76-322: Syntax error, statement will be ignored.
73 By State;
74 Run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.06 seconds
cpu time 0.04 seconds


75 Proc sort data= Bbq(where=(state='New York')) out=bbq1;
76 By State;
77 Run;

NOTE: Input data set is empty.
NOTE: The data set WORK.BBQ1 has 0 observations and 4 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.09 seconds
cpu time 0.07 seconds


78 Proc sort data= Bbq (where=(state='New York')) out=bbq1;
79 By State;
80 Run;

NOTE: Input data set is empty.
NOTE: The data set WORK.BBQ1 has 0 observations and 4 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.07 seconds
cpu time 0.04 seconds

 

 

Again I am not sure if I am doing this right. I am very new to this program.

PaigeMiller
Diamond | Level 26

Your data set BBQ is either empty, or it has no records for which STATE='New York'

 

You need to look at this data set and see what is in there.

--
Paige Miller
harveysarah0
Calcite | Level 5

So I realized it's NY and not New York.

 

PROC print data= Bbq (where=(state='NY'))
By State;
Run;

 

Would this be correct?

PaigeMiller
Diamond | Level 26

@harveysarah0 wrote:

So I realized it's NY and not New York.

 

PROC print data= Bbq (where=(state='NY'))
By State;
Run;

 

Would this be correct?


You can try it and find out yourself. I don't know if it is correct because I don't have your data set.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 12 replies
  • 1338 views
  • 2 likes
  • 3 in conversation