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

Hello,

I am trying to transpose a table, but variable is not numeric - it's a mix of characters and numbers (e.g. 1A, 1B, 1C, 2A, 2B, 2C, 2D, 2E, 3A, etc.... ).

When I am using a regular data step it shows an error "missing numeric suffix on a numbered variable" and "Mixing of implicit and explicit array subscripting is not allowed".

My table looks like this:

old table.png

And I am trying to convert it to this (per every student - a cumulative score for each of the programs:

Table new.png

I am using:

1      data new;

2      set old;

3      by ID;

4      KEEP ID FDBNS1A-FDBNS6C;

5      RETAIN FDBNS1A-FDBNS6C;

6      ARRAY aFDBNS (1A ; 6C) FDBNS1A-FDBNS6C;

7      IF first.ID then

8      DO;

9          DO i = 1A to 6C;

10         aFDBNS ( i ) = 0;

11      END;

12      END;

13           aFDBNS (FDGRP) = FDBNS;

14      IF last.ID then output;

15      run;

Lines 4, 5, 6 give "missing numeric suffix on a numbered variable" error;

Lines 10, 13 - "mixing of implicit and explicit array subscripting is not allowed".

I tried using ' ' as for a character variable but it did not work... Is it possible to transpose this way at all..?

Also..... Do I need to include any extra step to make sure that   if the same ID has a few courses (VAR1) that correspond to the same program and level (FDGRP) then the scores will be summed (like in the new table - underlined values).

Thanks so much!!!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why not just use PROC TRANSPOSE?  Run it through PROC SUMMARY or PROC SQL first to create sum for multiple observations.

proc transpose data=have out=want (drop=_name_) prefix=fdbns ;

  by id ;

  id fdgrp ;

  var fdbns ;

run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Why not just use PROC TRANSPOSE?  Run it through PROC SUMMARY or PROC SQL first to create sum for multiple observations.

proc transpose data=have out=want (drop=_name_) prefix=fdbns ;

  by id ;

  id fdgrp ;

  var fdbns ;

run;

a2veeram
Calcite | Level 5

Thank you so much Tom!

I used proc freq to get the totals (instead of proc summary / proc sql) and then used proc transpose. That worked equally well!

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