DATA Step, Macro, Functions and more

Input statement variable not recognized?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 130
Accepted Solution

Input statement variable not recognized?

Hi,

 

This looks right to me, but no matter what I do, SAS doesn't recognize the numerical variable NumSS.

 

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        

Accepted Solutions
Solution
‎04-25-2018 08:02 PM
Esteemed Advisor
Posts: 5,620

Re: Input statement variable not recognized?

Posted in reply to ManitobaMoose

The code

 

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

doesn't change the content of datasets learn.demographic2 or learn.survey2. It creates a new dataset named rename in library review. Variable numId is included in the new dataset.

 

PG

View solution in original post


All Replies
Super User
Posts: 23,980

Re: Input statement variable not recognized?

Posted in reply to ManitobaMoose

Can you explain what you're expecting from this portion of code? Adding comments would help us understand what you're trying to accomplish here. I suspect this is not correct. 

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

 

Super User
Posts: 23,980

Re: Input statement variable not recognized?

And after you create this data set you're still referencing the originals later (learn.demographic2) but those don't have the new variable, NumID...
Frequent Contributor
Posts: 130

Re: Input statement variable not recognized?

Hi,

 

I am learning SAS and part of that is trying to convert character variables to numeric, before then sorting and merging sets. The attempt here is to convert the character variable ID in each set to a numeric variable, which I am calling NumID. I thought the input statement as shown in the code would do this, but proc sort does not recognize the converted ID to NumID. Why not? Thanks.

 

 

Solution
‎04-25-2018 08:02 PM
Esteemed Advisor
Posts: 5,620

Re: Input statement variable not recognized?

Posted in reply to ManitobaMoose

The code

 

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

doesn't change the content of datasets learn.demographic2 or learn.survey2. It creates a new dataset named rename in library review. Variable numId is included in the new dataset.

 

PG
Frequent Contributor
Posts: 130

Re: Input statement variable not recognized?

I see. That make sense. Thanks!

Super User
Posts: 23,980

Re: Input statement variable not recognized?

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

run ;

This may be what you need but it's hard to say. It's not usually to see two SET statements like that. What are you trying to do there? Append two data sets (ie stack vertically?) 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 150 views
  • 0 likes
  • 3 in conversation