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

This is a answer from Learning SAS® by Example: A Programmer's Guide, Second Edition. But I think the rusults are not the what expected to get. 

 

Q: Using the permanent SAS data set Survey1, create a new, temporary SAS data set (Survey1)
where the values of the variables Ques1–Ques5 are reversed as follows:
1  5; 2  4; 3  3; 4  2; 5  1.

 

*13-1;
data survey1;
set learn.survey1;
array Ques{5} $ Q1-Q5;
do i = 1 to 5;
Ques{i} = translate(Ques{i},'54321','12345');
end;
drop i;
run;
title "List of SURVEY1 (rescaled)";

proc print data=learn.survey1;
run;
proc print data=survey1;
run;

 

List of SURVEY1 (rescaled)

 Obs Subj Q1 Q2 Q3 Q4 Q512345

00113542
00255443
00321211
00435142
00533333

List of SURVEY1 (rescaled)

 Obs Subj Q1 Q2 Q3 Q4 Q512345

00153124
00211223
00345455
00431524
00533333
1 ACCEPTED SOLUTION

Accepted Solutions
jz127323
Obsidian | Level 7

The first table is the original dataset

the second is after transformation

View solution in original post

8 REPLIES 8
ballardw
Super User

Where specifically do you have a question? Which specific values? Which observation (row)?

 

We don't have that data set so you need to be very explicit about your concern. From what I see the second output has all of the 1 changed to 5 and vice versa and 2 changed to 4 and vice versa. Isn't that what the introduction says to do?

 

(Not the way I would do this and actually not needed at all for 99% of activitiy, but these are learning examples)

 

You really need to provide two different TITLES for the two proc prints because your title implies that they are the same output but it isn't. One of the titles should say something about "before transformation" and the other "after transformation".

 

jz127323
Obsidian | Level 7

The first table is the original dataset

the second is after transformation

Reeza
Super User
Results look correct to me.
jz127323
Obsidian | Level 7

the old obs1: 

001 1 3 5 4 2

 

the new dataset, should it be:

001 2 4 5 3 1

 

thanks

andreas_lds
Jade | Level 19

@jz127323 wrote:

the old obs1: 

001 1 3 5 4 2

 

the new dataset, should it be:

001 2 4 5 3 1

 

thanks


Where is the problem? The new dataset is correct.

Note: I compared the original datasets, not the obs posted here.

@jz127323  you may want to show the code you have written, as text using "insert sas code" button, so that we can actually help.

Kurt_Bremser
Super User

@jz127323 wrote:

the old obs1: 

001 1 3 5 4 2

 

the new dataset, should it be:

001 2 4 5 3 1

 

thanks


No. From your description, 1 changes to 5 and 2 to 4 (and vice versa), while 3 remains unchanged. 

Reeza
Super User

@jz127323 wrote:

the old obs1: 

001 1 3 5 4 2

 

the new dataset, should it be:

001 2 4 5 3 1

 

thanks


No, reverse coding means reverse the values individually so that :

5 -> 1

4 -> 2

3 -> 3

2 -> 4

1 -> 5

 

You seem to want to reverse the order of the values in the row, ie what is in col5 goes to col1 which is not the correct interpretation of the question. 

jz127323
Obsidian | Level 7

Thanks for everyone's help. I totally misunderstood the meaning of the question. Not to exchange the values of columns, just change the value itselves. 

 

Thanks again!

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!

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
  • 8 replies
  • 940 views
  • 3 likes
  • 5 in conversation