You say you want to see these numbers "printed" -- what do you mean by that? Are you running PROC PRINT, PROC REPORT, PROC TABULATE??? Are you running PROC SQL?? Are you using ODS and if so, what is your destination of interest??
You show a "before" and "after" but do not indicate whether there are any counts or other values underneath your variable values. What is the name of the variable that contains the numbers 200, 201, etc??? What you describe seems to be that you want the variable values (from BEFORE) to become column headers???? If that is the case, do keep in mind that SAS variable names cannot start with a number -- they can only start with a character or an underscore.
You could create a custom report, written to FILE PRINT, using PUT statements, but without more information about your data, what the data represents and where the final "printed" report is going (destination) and what else should be on the final report, it's hard to give a definitive answer.
Can you explain a bit more about this task and the intended usage for the report with the newly printed/rearranged rows????
Sorry - the numbers are participant id numbers with the variable name IDNUM. I would like to print just the values of the variable IDNUM to represent a specific event: 200-202, 204 all passed a test. I need to create a report that shows these ranges, instead of each number individually.
Currently I'm using Base SAS and printing them using PROC PRINT. However, I am totally open to trying PROC REPORT or PROC TABULATE. I'm also open to using ODS.
This is my solution but I am not sure that this is what you need:.
length id $4;
/* Creating group variable i */;
if SUBSTR(id,4,1) = "*" then i+1;
/* Creating variable r for id ranges */;
length r1 $3 r $10;
if first.i then r1=SUBSTR(id,1,3);
if first.i and last.i then do; r=r1; output; end;
if not first.i and last.i then do; r=r1||"-"||id; end;
proc print data=a2;
Suppose you are doing survival statistical analysis.and asterisk denoted the censored data, right?
And also i do not think it is easy to do.Hope somebody gives a brief and directly resolution.
It my rude code.
input id : $;
/* Creating group variable i */
data asterisk data;
retain i 1;
if findc(id,'*') then do;
else output data;
length result $ 10 firstid $ 4;
retain result firstid;
if first.i and not last.i then firstid=id;
else if not first.i and last.i then do;
else if first.i and last.i then do;
proc sql noprint;
into :result separated by ','
%put the result is : &result;
Here is another way, writing to lst.
/* test data */
input id : $ @@;
200 201 202* 203 204* 205 206 207 208
209* 210 211 212 213 214 215* 216
/* this assumes that id^s are conjecutive */
length start finish range $20 comma $1;
retain start finish comma "";
set one end=end;
star = index(id,"*") > 0;
if star then do;
if missing(start) then return;
call missing(start, finish);
end; else do;
if missing(start) then start = id;
finish = id;
if end and not missing(start) then link outRange;
len = lengthn(comma);
put comma $varying. len @;
range = ifc(start=finish, start, catx("-", start, finish));
len = lengthn(range);
put range $varying. len @;