BookmarkSubscribeRSS Feed
gabras
Pyrite | Level 9

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?

 

 

2 REPLIES 2
ballardw
Super User

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.

Tom
Super User Tom
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2217 views
  • 3 likes
  • 3 in conversation