Dear experts.
I have a requirement to create a new variable to use it in my proc report to do the alignment as per data
the requirement is
I want to create pnum variable to get each test in one page in the report (i.e in one page different tests should not come) but in one page it can accommodate only 5 records .So that Iam creating pnum for first 5 test as 1 and next till the end of same test should be 2 .
same like for the next test "urin" first 5 is 3 and the rest is 4
like that i have so many tests ..
So if i create a variable like this I can use that in the report as page break
x test r pnum
1 blood 1 1
1 blood 2 1
1 blood 3 1
1 blood 4 1
1 blood 5 1
1 blood 6 2
1 blood 7 2
1 blood 8 2
2 urin 9 3
2 urin 10 3
2 urin 11 3
2 urin 12 3
2 urin 13 3
2 urin 14 4
Hi ambadi007,
You can do this as shown in the code example below:
data A;
length x 8 test $10;
input x test;
datalines;
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
2 urin
2 urin
2 urin
2 urin
2 urin
2 urin
;
proc sort data=A out=B;
by x;
run;
data C (drop=count);
set B;
by x;
r = _n_;
if first.x then count=0;
count + 1;
if mod(count-1, 5)=0 then pnum + 1;
run;
Hope this helps.
Hi ambadi007,
You can do this as shown in the code example below:
data A;
length x 8 test $10;
input x test;
datalines;
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
1 blood
2 urin
2 urin
2 urin
2 urin
2 urin
2 urin
;
proc sort data=A out=B;
by x;
run;
data C (drop=count);
set B;
by x;
r = _n_;
if first.x then count=0;
count + 1;
if mod(count-1, 5)=0 then pnum + 1;
run;
Hope this helps.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.