BookmarkSubscribeRSS Feed
4 REPLIES 4
Astounding
PROC Star

Suggestion:  start with reversing the order of the rows.  The other pieces of the problem are much more difficult.

srinath3111
Quartz | Level 8

Hi,

 

Reversing of all the observations in a data set is an easy process, We can do it in many forms.one of the solution.

 

data want;
do i=nobs to 1 by -1;
set have point=i nobs=nobs;
output;
end;
stop;
run;

gamotte
Rhodochrosite | Level 12

Hello,

 

Here is a start, using @srinath3111 solution for reversing row order.

 

proc sql noprint;
    SELECT nvar
    INTO :ncols
    FROM dictionary.tables
    WHERE libname="SASHELP" and memname="CLASS";
quit;

data _NULL_;
    set sashelp.vcolumn (where=(libname="SASHELP" and memname="CLASS")) end=eof;

    array lengths (&ncols.) $5. _TEMPORARY_;
    array columns (&ncols.) $32. _TEMPORARY_;

    lengths(&ncols.-varnum+1)=ifc(strip(type)='char',cats('$',length,'.'),cats(length,'.'));
    columns(&ncols.-varnum+1)=name;

    if eof then do;
        call execute('data want; format ');
        do i=1 to &ncols.;
            call execute(cat(' ',columns(i),lengths(i)));
        end;
        call execute('; do i=nobs to 1 by -1; set sashelp.class nobs=nobs point=i; output; end; stop; run;');

        /* reverse values of numeric variables */
        call execute('data want; set want; array nums(*) _NUMERIC_;');
        do i=1 to &ncols.;
            if substr(lengths(i),1,1) ne '$' then do;
                call execute(cat(columns(i),'=input(reverse(put(',columns(i),',',lengths(i),')),',lengths(i),');'));
            end;
        end;
        call execute('run;');
    end;

run;
Ksharp
Super User

If "values within cells" are all a string, then that would be easy for IML code and data step.

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
  • 4 replies
  • 2151 views
  • 0 likes
  • 5 in conversation