Hi everybody,
i'm using the proc transpose but it seems truncs some of the values of the ID statement.
A piece of the table is:
NUMERO_CASO | DESCRIZIONE_SERVIZIO | COUNT_SERV |
1-1107594808 | ESTRATTO PAGAMENTI SENZA PIN | 1 |
1-1107594808 | PENSIONI - DETTAGLIO RATA PAGAMENTO CON PIN | 7 |
1-1107594808 | PENSIONI - DETTAGLIO RATA PAGAMENTO SENZA PIN | 4 |
1-1107594808 | PIN INPS - GESTIONE RICHIESTE | 3 |
1-1107594808 | STATO DOMANDA | 2 |
1-1107594808 | VISUALIZZAZIONE CORRISPONDENZA INPS | 5 |
and the code i'm using is the following:
proc transpose data=from out=want ;
by numero_caso;
var count_serv;
id descrizione_servizio;
run;
but the error is:
ERROR: The ID value "'PENSIONI - DETTAGLIO RATA PAGAME'n" occurs twice in the same BY group.
As you see the value is has been truncated so the second and the third rows result equal to each other.
How can i solve this problem?
SAS has a limit of 32 characters for a variable name. Discounting the quotes for the name literal the ID variable is truncated to 32 characters.
You might consider changing the values of the variable to something shorter and then assigning labels to get the longer text to appear form most procedures in output or table views.
Personally I hate trying to type variables longer than about 12 characters and seldom use them and basically never use name literal variables.
Use a varaible with shorter values for the ID variable and use the existing one for the IDLABEL variable instead. If you do not have another variable you can use then make one. Here is a method to just number the distinct values found.
data have ;
length NUMERO_CASO $15 DESCRIZIONE_SERVIZIO $50 COUNT_SERV 8;
infile cards dsd dlm='|' truncover ;
input NUMERO_CASO DESCRIZIONE_SERVIZIO COUNT_SERV ;
cards;
1-1107594808|ESTRATTO PAGAMENTI SENZA PIN|1
1-1107594808|PENSIONI - DETTAGLIO RATA PAGAMENTO CON PIN|7
1-1107594808|PENSIONI - DETTAGLIO RATA PAGAMENTO SENZA PIN|4
1-1107594808|PIN INPS - GESTIONE RICHIESTE|3
1-1107594808|STATO DOMANDA|2
1-1107594808|VISUALIZZAZIONE CORRISPONDENZA INPS|5
;
proc sql ;
create table fmt as
select distinct DESCRIZIONE_SERVIZIO as START
from have
;
quit;
data fmt;
fmtname='id';
type='i';
label+1;
set fmt;
run;
proc format cntlin=fmt fmtlib;
run;
data step1;
set have;
id = input(DESCRIZIONE_SERVIZIO,id.);
run;
proc transpose data=step1 prefix=SERV out=want(drop=_name_) ;
by NUMERO_CASO;
id id;
idlabel DESCRIZIONE_SERVIZIO;
var COUNT_SERV;
run;
proc print data=want ;
run;
proc print data=want label;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.