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

Hello everybody!

Can I build a field with the function SUBSTR in the proc report ?

I'm trying to do something like this, but it doesn't working.

proc report data=rsm_negs;

col Mercado Qtd Fin papel;

define Mercado / group;

define qtd / sum;

define fin / sum;

define mercadoria / group computed;

compute mercadoria;

mercadoria = substr(Papel,1,3);

endcomp;

run;

Tk's in advanced!!

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

;Hi:

  The left to right order of your items in the COLUMN statement will be important.  I do not see MERCADORIA in your COLUMN statement and I am not on a system where I have SAS to test with, but if you had this:

col Mercado Qtd Fin papel mercadoria;

with MERCADORIA appearing after PAPEL in the COLUMN statement, then you should be able to do this in a COMPUTE block:

define mercadoria / computed "Mercadoria";

compute mercadoria / character length=3;

  mercadoria = substr(Papel,1,3);

endcomp;

 

You cannot have a usage of GROUP -and- COMPUTED in your DEFINE statement for MERCADORIA. So if you need to collapse rows for summarizing based on the first 3 characters of PAPEL, you might need to create MERCADORIA as a variable in your dataset.

cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

;Hi:

  The left to right order of your items in the COLUMN statement will be important.  I do not see MERCADORIA in your COLUMN statement and I am not on a system where I have SAS to test with, but if you had this:

col Mercado Qtd Fin papel mercadoria;

with MERCADORIA appearing after PAPEL in the COLUMN statement, then you should be able to do this in a COMPUTE block:

define mercadoria / computed "Mercadoria";

compute mercadoria / character length=3;

  mercadoria = substr(Papel,1,3);

endcomp;

 

You cannot have a usage of GROUP -and- COMPUTED in your DEFINE statement for MERCADORIA. So if you need to collapse rows for summarizing based on the first 3 characters of PAPEL, you might need to create MERCADORIA as a variable in your dataset.

cynthia

Abud
Calcite | Level 5

Tk's!! Cynthia!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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