DATA Step, Macro, Functions and more

Proc TRANSPOSE truncs values of the ID statement

Reply
Contributor
Posts: 20

Proc TRANSPOSE truncs values of the ID statement

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_CASODESCRIZIONE_SERVIZIOCOUNT_SERV
1-1107594808ESTRATTO PAGAMENTI SENZA PIN1
1-1107594808PENSIONI - DETTAGLIO RATA PAGAMENTO CON PIN7
1-1107594808PENSIONI - DETTAGLIO RATA PAGAMENTO SENZA PIN4
1-1107594808PIN INPS - GESTIONE RICHIESTE3
1-1107594808STATO DOMANDA2
1-1107594808VISUALIZZAZIONE CORRISPONDENZA INPS5

 

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?

 

 

Super User
Posts: 11,343

Re: Proc TRANSPOSE truncs values of the ID statement

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.

Super User
Super User
Posts: 7,059

Re: Proc TRANSPOSE truncs values of the ID statement

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;

image.png

Ask a Question
Discussion stats
  • 2 replies
  • 106 views
  • 2 likes
  • 3 in conversation