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

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        
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

6 REPLIES 6
Reeza
Super User

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 ; 

 

Reeza
Super User
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...
ManitobaMoose
Quartz | Level 8

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.

 

 

PGStats
Opal | Level 21

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
ManitobaMoose
Quartz | Level 8

I see. That make sense. Thanks!

Reeza
Super User
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?) 

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
  • 1955 views
  • 0 likes
  • 3 in conversation