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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1491 views
  • 1 like
  • 2 in conversation