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

I am trying to create a sequence number to be placed at the end of a file name for a proc export.

Work.seq_nbr will contain the number I want to start with and then the datastep increment will increment that number by one and put a leading zero before it.  If the seq_nbr starts off at say 270 then I want 0271 to be &seq_nbr_pad in my proc export.

I just can't figure out how to make it a macro variable in my datastep or I need help in finding a way to do this.

 

data increment(keep=seq_nbr_pad);

length seq_nbr_txt $ 4 seq_nbr_pad $ 4;

set work.seq_nbr;

/* read charvar as number, then format with leading zeroes */

/* then put result into padded */

seq_nbr = seq_nbr+1;

seq_nbr_txt = put(seq_nbr,4.);

seq_nbr_pad = put(input(seq_nbr_txt,best4.),z4.);

%let seq_nbr=seq_nbr_pad;

run;

PROC EXPORT

DATA=increment

OUTFILE="\\Home1\userid\GMF_&SEQ_NBR_PAD..csv"

DBMS=CSV REPLACE;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

%LET can't be part of a DATA step.  Here's an alternative method to create your macro variable:

 

data _null_;

set work.seq_nbr (keep=seq_nbr);

call symput('seq_nbr_pad', put(seq_nbr+1, z4.));

run;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

%LET can't be part of a DATA step.  Here's an alternative method to create your macro variable:

 

data _null_;

set work.seq_nbr (keep=seq_nbr);

call symput('seq_nbr_pad', put(seq_nbr+1, z4.));

run;

sgtrun
Fluorite | Level 6

Works perfectly.  Thank you so much.

ballardw
Super User

Are you actually going to export the exact same data set to multiple files? Unless you change your Increment data set that will be the likely effect.

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
  • 3 replies
  • 5027 views
  • 0 likes
  • 3 in conversation