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

Hello everyone,

 

I have an SAS question in terms of the "index" when doing "rename", as follows:

 

The SAS data set WORK.TEST has an index on the variable ID and the following    
                                                                                
SAS program is submitted.                                                       
                                                                                
data WORK.TEST;                                                                 
  set WORK.TEST(                                                                
keep=ID Var_1 Var_2                                                             
rename=(ID=ID_Code);                                                            
Total=sum(Var_1 Var_2);                                                         
run;                                                                            
                                                                                
                                                                                
Which describes the result of submitting the SAS program?                       
                                                                                
A.                                                                              
The index on ID is deleted.                                                     
                                                                                
B.                                                                              
The index on ID is updated as an index on ID_Code.      

C.                                                                              
The index on ID is deleted and an index on ID_Code is created.                  
                                                                                
D.                                                                              
The index on ID is recreated as an index on ID_Code.  

The answer seems A, and I wonder why. Any help would be appreciated.

I chose C.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Indeed. - Actually, if you run the code as given above, the dataset test will not be replaced because of syntax errors. The code is missing a comma and a closing parenthesis.

PG

View solution in original post

5 REPLIES 5
PGStats
Opal | Level 21

The datastep creates a new dataset for which no index is defined.

PG
jc3992
Pyrite | Level 9

Thank you very much! 

so the new data set (the new WORK.TEST) has no index?

Thank you!

PGStats
Opal | Level 21

Indeed. - Actually, if you run the code as given above, the dataset test will not be replaced because of syntax errors. The code is missing a comma and a closing parenthesis.

PG
Reeza
Super User
Even if you use the same data set name, it essentially deletes and replace it. This is bad programming style and should not be used.
PeterClemmensen
Tourmaline | Level 20

Yes, the answer is A.

 

If you want to preserve the index, use the Copy Statement in PROC DATASETS with Index=YES (Default).

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 989 views
  • 6 likes
  • 4 in conversation