Calcite | Level 5

Sort by State

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
Diamond | Level 26

Re: Sort by State

@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
12 REPLIES 12
Tourmaline | Level 20

Re: Sort by State

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;``````
Calcite | Level 5

Re: Sort by State

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

Tourmaline | Level 20

Re: Sort by State

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

Diamond | Level 26

Re: Sort by State

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
Calcite | Level 5

Re: Sort by State

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

Diamond | Level 26

Re: Sort by State

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

--
Paige Miller
Calcite | Level 5

Re: Sort by State

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

Diamond | Level 26

Re: Sort by State

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

--
Paige Miller
Calcite | Level 5

Re: Sort by State

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.

Diamond | Level 26

Re: Sort by State

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
Calcite | Level 5

Re: Sort by State

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

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

Would this be correct?

Diamond | Level 26

Re: Sort by State

@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
Discussion stats
• 12 replies
• 1027 views
• 2 likes
• 3 in conversation