BookmarkSubscribeRSS Feed
Cyril_FR
Calcite | Level 5
Hi,

How to do the same thing that below (ie the same column names) with a boucle do?

data final4 (drop=_label_);
set final3;
COL1b=lag(seq1);
COL2b=lag(seq2);
COL3b=lag(seq3);
COL4b=lag(seq4);
COL5b=lag(seq5);
run;

thanks by advance
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Not totally sure of the question, possibly interested in a SAS coding technique requiring fewer lines to accomplish the objective?

If yes, then using a SAS ARRAY to declare the two sets of SAS variables is a technique I use often when there are repeating variable groups to assign -- sample code below, given the poster's submission:

data final4 (drop=_label_);
set final3;
array acol (*) col1b col2b col3b col4b col5b;
array aseq (*) seq1-seq5;
do i=1 to dim(acol);
acol(i) = lag(aseq(i))
end;
run;

Scott Barry
SBBWorks, Inc.
Cyril_FR
Calcite | Level 5
Thank you, it's exactly what i wanted to do.
My programs will looks better!
Cyril

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