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

 

Hi All,

 

Running SAS 9.4M5.

 

I am looking to clean up a list of potential variable names and as a result I decided to create a custom function.  The problem is, even though I have explicitly set the length (excessively large at 500) of the resulting variable, I still max out at 20 characters and some of the data is being truncated.  I have tested the PRXCHANGE syntax in a stand alone datastep and it works as desired, however when I copy the exact syntax into FCMP the truncation occurs.

 

The following is a subset list of potential variable names:

 

DATA HAVE;
INFILE DATALINES DLM=",";
INPUT BUFFER : $200.;
DATALINES;
Policy Number
Vehicle Sequence Number
Vehicle Suffix
Vehicle Seqno - Financials
Status
;
RUN;

The Proc FCMP step:

 

PROC FCMP OUTLIB=WORK.FUNCTIONS.BUSREQS;

LENGTH NEW_NAME $ 500;

FUNCTION CLEANCOLUMNNAMES(OLD_NAME $) $ 500;
NEW_NAME = PRXCHANGE('s/[^a-z A-Z 0-9_]/ /',-1,TRIM(LEFT(OLD_NAME)));

RETURN (NEW_NAME);

ENDSUB;

RUN;

OPTIONS CMPLIB = (WORK.FUNCTIONS);

Datastep using the newly created variable:

 

DATA WANT;
SET HAVE;
LENGTH TEST $ 500;
TEST = CLEANCOLUMNNAMES(BUFFER);
RUN;

Results showing the truncated results:

 

Capture.PNG

 

Any assistance would be greatly appreciated.

 

Regards,

Scott

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Include your LENGTH statement in FUNCTION .

 


PROC FCMP OUTLIB=WORK.FUNCTIONS.BUSREQS;


FUNCTION CLEANCOLUMNNAMES(OLD_NAME $) $ 500;
LENGTH NEW_NAME $ 500; /*<-- Here*/

NEW_NAME = PRXCHANGE('s/[^a-z A-Z 0-9_]/ /',-1,TRIM(LEFT(OLD_NAME)));

RETURN (NEW_NAME);

ENDSUB;

RUN;

View solution in original post

3 REPLIES 3
Ksharp
Super User

Include your LENGTH statement in FUNCTION .

 


PROC FCMP OUTLIB=WORK.FUNCTIONS.BUSREQS;


FUNCTION CLEANCOLUMNNAMES(OLD_NAME $) $ 500;
LENGTH NEW_NAME $ 500; /*<-- Here*/

NEW_NAME = PRXCHANGE('s/[^a-z A-Z 0-9_]/ /',-1,TRIM(LEFT(OLD_NAME)));

RETURN (NEW_NAME);

ENDSUB;

RUN;
Scott_Mitchell
Quartz | Level 8

Thank you @Ksharp .  I will give this a shot tomorrow.

Scott_Mitchell
Quartz | Level 8
Worked perfectly. Thank you.

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
  • 3 replies
  • 1100 views
  • 1 like
  • 2 in conversation