BookmarkSubscribeRSS Feed
ManitobaMoose
Quartz | Level 8

 

 

This code is generating a ton of errors. I am not sure why the input statement is not correct. The original variable ID is a character and I want to convert it to numeric, and then merge sets. The code is below. Thanks.

 

Libname Review'/folders/myfolders/Review' ;
Libname Learn'/folders/myfolders/Learn' ;  
Libname myformat'/folders/myfolders/sasuser.v94' ; 
Options fmtsearch=(myformat) ;
Options mergenoby=error ; 

proc sort data=learn.demographic2 ; 
	NumID = Input(ID, 3.) ;
	by NumID ;
run ; 

proc sort data=learn.survey2 ;  
	NumID = Input(ID, 3.) ;
	by NumID ; 
run ; 

Data review.Prob10_13 ; 
	merge learn.demographic2(in=indemographic2)
	      learn.survey2(in=inSurvey2) ;
	by NumID ; 
	If Indemographic2 InSurvey2 ; 
run ; 

proc print data=review.Prob10_13 noobs ; 
run ; 
6 REPLIES 6
ManitobaMoose
Quartz | Level 8

The error log is below.

 

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 61         
 62         Libname Review'/folders/myfolders/Review' ;
 NOTE: Libref REVIEW was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders/Review
 63         Libname Learn'/folders/myfolders/Learn' ;
 NOTE: Libref LEARN refers to the same physical library as LEARN2.
 NOTE: Libref LEARN was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders/Learn
 64         Libname myformat'/folders/myfolders/sasuser.v94' ;
 NOTE: Libref MYFORMAT refers to the same physical library as SASUSER.
 NOTE: Libref MYFORMAT was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders/sasuser.v94
 65         Options fmtsearch=(myformat) ;
 66         Options mergenoby=error ;
 67         
 68         proc sort data=learn.demographic2 ;
 69         NumID = Input(ID, 3.) ;
             _____
             180
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 70         by NumID ;
 ERROR: Variable NUMID not found.
 71         run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 72         
 
 
 73         proc sort data=learn.survey2 ;
 74         NumID = Input(ID, 3.) ;
             _____
             180
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 75         by NumID ;
 ERROR: Variable NUMID not found.
 76         run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 77         
 
 
 78         Data review.Prob10_13 ;
 79         merge learn.demographic2(in=indemographic2)
 80               learn.survey2(in=inSurvey2) ;
 81         by NumID ;
 82         If Indemographic2 InSurvey2 ;
                               _________
                               22
 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, 
               LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  
 
 83         run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set REVIEW.PROB10_13 may be incomplete.  When this step was stopped there were 0 observations and 10 variables.
 WARNING: Data set REVIEW.PROB10_13 was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 84         
 85         proc print data=review.Prob10_13 noobs ;
 86         run ;
 
 NOTE: There were 9 observations read from the data set REVIEW.PROB10_13.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.11 seconds
       cpu time            0.10 seconds
       
 
 87         
 88         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 101        
 
ballardw
Super User

Start here:

proc sort data=learn.demographic2 ;
 69         NumID = Input(ID, 3.) ;
             _____

SORT sorts, it does not do any calculation. The main thing sort will expect are BY to express the order a sort occurs in or a Key statement to indicate which variable(s) might be used for a key sort.

82         If Indemographic2 InSurvey2 ;
                               _________
                               22
 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, 
               LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

 

 

 

Then with

82         If Indemographic2 InSurvey2 ;
                               _________
                               22
 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, 
               LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

IF expects some that can be compared. A single variable is evaluated to 0 for false or non-0 for true. Two variables will require some explicit comparison such as

 

      If Indemographic2 and InSurvey2 ;

which is true and the record kept when both variables are true (1 in this case).

 

notice that AND is one of the words in the "expecting one of the following" list. SAS recognized InSurvey2 as a variable and so knows something is missing.

Tom
Super User Tom
Super User

You cannot have an assignment statement in the middle of a PROC SORT step.

Those would need to be in a DATA step.

 

Astounding
PROC Star

PROC SORT doesn't let you create new variables.  It only sorts the existing data.

 

If you want to create NUM_ID, you need a DATA step to do that.  Then run PROC SORT next.

 

For  your later error regarding the IN= variables, please explain what you want that section to accomplish.

 

***************** EDITED:

 

OK, looks like it's a little crowded here.  Time for me to go home!

ManitobaMoose
Quartz | Level 8

Ok, for the IN= I just forgot the AND. That is no problem.

 

The bigger issue I am having is with renaming the vars. Below does not seem to work, and the variable NumID is not recognized.

Libname Review'/folders/myfolders/Review' ;
Libname Learn'/folders/myfolders/Learn' ;  
Libname myformat'/folders/myfolders/sasuser.v94' ; 
Options fmtsearch=(myformat) ;
Options mergenoby=error ; 

Data review.rename_vars ; 
	Set learn.demographic2 ; 
	NumID = Input(ID, 3.) ; 
	Set learn.survey2 ; 
	NumID = Input(ID, 3.) ;
run ; 
	
	
proc sort data=learn.demographic2 ; 
	by NumID ;
run ;

proc sort data=learn.survey2 ; 
	by NumID ;
run ;

Error log:

 

Errors (2)
ERROR: Variable NUMID not found.
ERROR: Variable NUMID not found.
Warnings
Notes (20)

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 61         
 62         Libname Review'/folders/myfolders/Review' ;
 NOTE: Libref REVIEW was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders/Review
 63         Libname Learn'/folders/myfolders/Learn' ;
 NOTE: Libref LEARN refers to the same physical library as LEARN2.
 NOTE: Libref LEARN was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders/Learn
 64         Libname myformat'/folders/myfolders/sasuser.v94' ;
 NOTE: Libref MYFORMAT refers to the same physical library as SASUSER.
 NOTE: Libref MYFORMAT was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders/sasuser.v94
 65         Options fmtsearch=(myformat) ;
 66         Options mergenoby=error ;
 67         
 68         Data review.rename_vars ;
 69         Set learn.demographic2 ;
 70         NumID = Input(ID, 3.) ;
 71         Set learn.survey2 ;
 72         NumID = Input(ID, 3.) ;
 73         run ;
 
 NOTE: Format $LIKERT was not found or could not be loaded.
 NOTE: Format $LIKERT was not found or could not be loaded.
 NOTE: Format $LIKERT was not found or could not be loaded.
 NOTE: Format $LIKERT was not found or could not be loaded.
 NOTE: Format $LIKERT was not found or could not be loaded.
 NOTE: There were 4 observations read from the data set LEARN.DEMOGRAPHIC2.
 NOTE: There were 4 observations read from the data set LEARN.SURVEY2.
 NOTE: The data set REVIEW.RENAME_VARS has 4 observations and 11 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 74         
 75         
 76         proc sort data=learn.demographic2 ;
 77         by NumID ;
 ERROR: Variable NUMID not found.
 78         run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 79         
 
 
 80         proc sort data=learn.survey2 ;
 81         by NumID ;
 ERROR: Variable NUMID not found.
 82         run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 83         /*proc sort data=learn.demographic2 ;
 84         by ID ;
 85         run ;
 86         
 87         proc sort data=learn.survey2 ;
 88         by ID ;
 89         run ;
 90         
 91         Data review.Prob10_13 ;
 92         merge learn.demographic2(in=indemographic2)
 93               learn.survey2(in=inSurvey2) ;
 94         by ID ;
 95         If Indemographic2=1 AND InSurvey2=1 ;
 96         run ; */
 97         
 98         /*proc print data=review.Prob10_13 noobs ;
 99         run ; */
 100        
 
 
 101        proc print data=review.rename_vars noobs;
 102        run ;
 
 NOTE: There were 4 observations read from the data set REVIEW.RENAME_VARS.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.10 seconds
       cpu time            0.11 seconds
       
 
 103        
 104        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 117        
Astounding
PROC Star

You must Must MUST learn the meaning of basic statements.  Take this DATA step:

 

Data review.rename_vars ; 
	Set learn.demographic2 ; 
	NumID = Input(ID, 3.) ; 
	Set learn.survey2 ; 
	NumID = Input(ID, 3.) ;
run ; 

 

The DATA statement names the data set being created.  The SET statement names the data set being read in.  (At a more advanced level, there's definitely more to it, but let's take the basics here.)

 

All the subsequent changes made by your programming statements (such as creating NumID) have zero impact on the contents of learn.demographics2.  All the changes are part of the data set being created, review.rename_vars.  So when  your later steps use learn.demographics2, those steps are using a data set that does not contain NumID.

 

Now I'm not sure what your plan was, and why you are using two SET statements.  But this DATA step definitely changed the contents of review.rename_vars.  You may need to rebuild it. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 870 views
  • 4 likes
  • 4 in conversation