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

I have a dataset with identifiers that I do not want in the final report.

For example, it is generated from this code:

 

data one;
	array idarr{10} $ idarr1-idarr10 ('a','b','c','d','e','f','g','h','i','j');
	do a=1 to 10;
		iden=idarr[a];
		do b=1 to 3;
			do c=1 to 2;
				output;
			end;
		end;
	end;
	drop a;
run;

Using the following, the variables span as I would like

proc report data=one spanrows;
	columns iden b c;
	define iden	/ 'id' order order=internal;
	define b	/ 'B' order order=internal;
	define c	/ 'C' order order=internal;
run;

I do not want the "iden" variable to be in the report, but want a counter [that increments with each change of iden] instead, I wrote the following:

proc report data=one spanrows;
	columns iden nobs3 b c;
	define iden		/ 'id' order order=internal;
	define nobs3	/ 'id obs 3' computed;
	define b		/ 'B' order order=internal;
	define c		/ 'C' order order=internal;

	compute nobs3;
		if not missing(iden) then dsobs3+1;
		nobs3=dsobs3;	
	endcomp;
run;

the problem is nobs3 is repeated for every row.

Is there a way to make the computed variable nobs3 span in the same way iden does?

 

One way I know to make it work is to create nobs3 in the dataset that is being passed to report, but, if possible, I was hoping to create it within report.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Why not use a format?

proc sql;
  create table _F as
  select START, monotonic() as LABEL, '$iden' as FMTNAME, 'C' as TYPE
  from (select unique IDEN as START from ONE);
proc format cntlin=_F; run;

proc report data=ONE spanrows;
	columns IDEN B C;
	define IDEN / 'id' order order=internal format=$iden.;
	define B	/ 'B' order order=internal;
	define C	/ 'C' order order=internal;
run;

 

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Why not use a format?

proc sql;
  create table _F as
  select START, monotonic() as LABEL, '$iden' as FMTNAME, 'C' as TYPE
  from (select unique IDEN as START from ONE);
proc format cntlin=_F; run;

proc report data=ONE spanrows;
	columns IDEN B C;
	define IDEN / 'id' order order=internal format=$iden.;
	define B	/ 'B' order order=internal;
	define C	/ 'C' order order=internal;
run;

 

jtcowder
Fluorite | Level 6

That certainly works, I would not have thought of that.

Thank you for the suggestion, it is much appreciated.

novinosrin
Tourmaline | Level 20

Sir @ChrisNZ  priceless solution. Jealous of how you think. I don't like you sorry.lol. 🙂 Brings me to ground zero and tears that kind of thought/application would ever strike my mind. Well done!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1246 views
  • 3 likes
  • 3 in conversation