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

Greetings everyone,

I got this file after transpose but only need to keep one row of key. I know proc sort can delete duplicates but I need the items stay the same order. 

 

data example;

input ID $ Item105 $ Item124 $ Item 992 $ Item020 Item 035 $ Item 021 Item025 Item789;

datalines;

001 A B . 1 D . 1 A

002 .  B C 1 . 1 . A

003 . . C 1 D 1 1 A

004 A . . 1 D . 1 A 

005 . . C . D 1 1 .

006 A B . . D 1 . A

007 A B . 1 . 1 . A

008 . . C 1 D . . A

009 A . C . . 1 . .

010 . . . 1 D 1 1 A

011 . B C . D 1 . A

;

 

data want;

input ID $ Item105 $ Item124 $ Item 992 $ Item020 Item 035 $ Item 021 Item025 Item789;

datalines;

001 A B C 1 D 1 1 A

;

 

How will I be able to achieve this? Thank you so much in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Wouldn't it be easier to get the answer key from the original dataset rather than after you have transposed it?  Probably a simple select distinct query in SQL or a PROC SORT NODUPKEY step.

 

You could trick the UPDATE function into doing what you want.  But you will need some constant value variable to use as the BY variable.

data step1;
  set example;
  if _n_=1 then dummy=id;
  retain dummy;
run;

data want;
  update step1(obs=0) step1;
  by dummy;
run;

 

View solution in original post

5 REPLIES 5
lapetitemaman
Calcite | Level 5
Sorry, Item789 should be Item789 $.
Tom
Super User Tom
Super User

I don't see any transpose here or how transpose would have anything to do with this.

 

Can you explain the reason you get that value as the output?

Why does ID='001'?  What happens when ITEM105 has values other than 'A' or ' '?  Which value would you want?

lapetitemaman
Calcite | Level 5
The example file is what I have obtained after transposing another file. There is no transposing here. The values A, B, C, D, and 1 are the correct answers (or key) and each ID were administered different items. The values I want are only one row of values (with no missing value) that I can use as the key file for another program. I can change and rename the first variable after I obtain one row of values.
Tom
Super User Tom
Super User

Wouldn't it be easier to get the answer key from the original dataset rather than after you have transposed it?  Probably a simple select distinct query in SQL or a PROC SORT NODUPKEY step.

 

You could trick the UPDATE function into doing what you want.  But you will need some constant value variable to use as the BY variable.

data step1;
  set example;
  if _n_=1 then dummy=id;
  retain dummy;
run;

data want;
  update step1(obs=0) step1;
  by dummy;
run;

 

lapetitemaman
Calcite | Level 5
The reason I used transpose to get this file is because I had a transposed response file and these two files need to match (in terms of item order, examinee ID order). I wish the item order followed a constant value... Thank you for the help.

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
  • 298 views
  • 0 likes
  • 2 in conversation