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

Hi Community,

 

Kind of confused now, can proc transpose do this 

 

have

SubjectVar1Var2Var3Var4Var5Var6Var7Var8Var9Var10Var11Var12Var13Var14Var15Var16Var17Var18Var19Var20
AB280294288270247259220252240206220262296248221233248253217270
CD267238252254272278244215224224290228224242205284255253291283

 

want

SubjectColnameValue
ABVar1280
ABVar2294
ABVar3288
ABVar4270
ABVar5247
ABVar6259
ABVar7220
ABVar8252
ABVar9240
ABVar10206
ABVar11220
ABVar12262
ABVar13296
ABVar14248
ABVar15221
ABVar16233
ABVar17248
ABVar18253
ABVar19217
ABVar20270
CDVar1267
CDVar2238
CDVar3252
CDVar4254
CDVar5272
CDVar6278
CDVar7244
CDVar8215
CDVar9224
CDVar10224
CDVar11290
CDVar12228
CDVar13224
CDVar14242
CDVar15205
CDVar16284
CDVar17255
CDVar18253
CDVar19291
CDVar20283

 

Thank you!

1 ACCEPTED SOLUTION
7 REPLIES 7
novinosrin
Tourmaline | Level 20
data have;
input Subject $	Var1	Var2	Var3	Var4	Var5	Var6	Var7	Var8	Var9	Var10	Var11	Var12	Var13	Var14	Var15	Var16	Var17	Var18	Var19	Var20;
cards;
AB	280	294	288	270	247	259	220	252	240	206	220	262	296	248	221	233	248	253	217	270
CD	267	238	252	254	272	278	244	215	224	224	290	228	224	242	205	284	255	253	291	283
;

proc transpose data=have out=want(rename=(col1=value));
 by subject;
 var var1-var20;
run;
zimcom
Pyrite | Level 9

@Kurt_Bremser @novinosrin 

That was quick, thank you both! 

zimcom
Pyrite | Level 9
what if the variables in daatset "have" are random variable name (not like Var1, Var2, Var3)?
FreelanceReinh
Jade | Level 19

@zimcom wrote:
what if the variables in daatset "have" are random variable name (not like Var1, Var2, Var3)?

Hi @zimcom,

 

If all these variables are numeric (as they seem to be in your example), you can even omit the VAR statement, as PROC TRANSPOSE will transpose all numeric variables by default. Otherwise you can use a name range list of the form

var firstvar--lastvar;

(i.e., var1--var20 in your example), where the variable number (see column headed "#" in PROC CONTENTS output) defines the order of the list. The VAR statement also accepts combinations of several lists and variable names, not to mention macro variables containing tailored lists of variable names.

 

zimcom
Pyrite | Level 9
Thank you! Really appreciated your help!
Kurt_Bremser
Super User

If there is any kind of pattern to the variable names, a query of DICTIONARY.COLUMNS in SQL can be used to store the variable names in a macro variable.

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
  • 7 replies
  • 670 views
  • 4 likes
  • 4 in conversation