Help using Base SAS procedures

stripping leading zeros

Posts: 65

stripping leading zeros

I'm using a data step to build up multiple ftp put statements and I need to remove all leading zeros. The person ID is the value with the leading zeros. I'm also trying to figure how to put the quit keyword after the last occurence. I thought last. would work but it isn't coming out correctly.

Below is the data step.

data _null_;
set work.display_data;
by person_id_nb;
file max_pics;

line1 = 'cd incoming';
line2 = 'put \\location\of\thepics' ||trim(person_id_nb) || '.jpg';
Line3 = 'quit';

if _N_ = 1 then put line1;
put line2;
if _N_ = lastobs then put line3;

Super Contributor
Super Contributor
Posts: 3,174

Re: stripping leading zeros

Suggest checking the forum archives with SEARCH -- it's a popular topic. Also, you could use the END= keyword on the SET statement to detect the end-of-file condition.

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
Frequent Contributor
Posts: 106

Re: stripping leading zeros


try somewhat along these lines:

data ids ; id='00123' ; output ; id='04567' ; output ; stop ; run ;
data _null_ ;
set ids end=lastobs ;
if _n_ = 1 then put 'cd incoming' ;
idnum = input(id,best.) ;
put 'put \\your_location\' idnum +(-1) '.jpg' ;
if lastobs then put 'quit' ;
run ;

Robert Message was edited by: Robert.Bardos
Posts: 65

Re: stripping leading zeros

That works great but what if the id's are coming from a temporary data set?
Posts: 65

Re: stripping leading zeros

I got it to work. Thanks again for the help.

Ask a Question
Discussion stats
  • 4 replies
  • 3 in conversation