Achieved this by using FORMAT statement, able to print 'IND' on all records.
Post test data in the form of a datastep, we cannot see your computer!
data want; set have; if mod(_n_,100)=0 then flag=1; run;
Not tested.
Please review the how to post a question guide below the Post button. Provide test data in the form of a datastep and show what the output should look like.
Hence the response remains the same:
data want; set have; if mod(_n_,100)=0 then indicator="IND"; run;
I will try once more. Please provide test data in the form of a datastep which accurately shows your problem. What you have posted neither shows the data in a form that we can run, nor does it illustrate what to do or match the thread title. Let me take my time to type some test data in for you and show you how to do it:
Here is some test data which we can run and have something to work with:
data have; input name $ age sex $; datalines; Nesco 43 M Greg 36 M Nesco 43 M Greg 36 M Nesco 43 M Greg 36 M Nesco 43 M Greg 36 M Nesco 43 M Greg 36 M ; run;
Your thread title was how to flag X number of rows each time, to which I presented the code:
data want; set have; if mod(_n_,3)=0 then indicator="IND"; run;
If you put these two together you will fin that every 3rd row is flagged. If this is not what you want, please describe thoroughly, providing test data in the form of a datastep and showing what you want out at the end.
Hello,
I will take a wild guess and assume that you want to create a new column at a predefined position in the dataset.
Here is a program that adds a column in sashelp.class in third position :
%let pos=3;
proc sql;
SELECT name
INTO :before_pos separated by ','
FROM dictionary.columns
WHERE libname="SASHELP" AND memname="CLASS" AND varnum<&pos.;
SELECT name
INTO :after_pos separated by ','
FROM dictionary.columns
WHERE libname="SASHELP" AND memname="CLASS" AND varnum>=&pos.;
CREATE TABLE WANT AS
SELECT &before_pos., "IND" AS newvar, &after_pos.
FROM sashelp.class;
quit;
Achieved this by using FORMAT statement, able to print 'IND' on all records.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.