BookmarkSubscribeRSS Feed
Kinston
Calcite | Level 5

Hi Experts,

 

i need some information on how i can split some tables into two equal parts. the codes are in many parts with many macros but i have taken just the part that needs some mentainance. there are five tables. each one has 8 rows and a header making 9.

i want a short program that can split each into two equal parts with  this title for one  “US Imports from Company Defined “||put(ctry_rgn,$rgn2fmt.);"  and this title for the other  US Exports from Company Defined “||put(ctry_rgn,$rgn2fmt.);

ithe codes below is what i have been trying to split.

 

 

*Prepare data in the report format;

 

%prepdat3;

run;

 

 

***************************************************************************************;

%macro driver;

     **************End changes, do not touch below this for reporting********************************;

     data _null_;

          endhist=&endhist;

          beghist=intnx('year',endhist, -5);/*5years*/

          call symput ('beghist', trim(left(beghist)));

     run;

 

     %let page_count=36;/*one less then start page*/

 

     *loop over regions;

     %do argn=1 %to 5; /* */

          %let page_count=%eval(&page_count+1);

 

          %mk_table3(&argn);

          run;

 

          %end;

%mend driver;

 

*********************************************************************************************;

*formats;

*********************************************************************************************;

%macro mk_formats;

 

     *formats;

%macro mk_formats;

 

     proc format;

          value mx1fmt

              1='Imports'

              2='Exports'

              4='Imports'

              3='Exports'

          ;

 

     proc format;

          value mx2fmt

              1='Import'

              2='Export'

              4='Import'

              3='Export'

          ;

 

     proc format;

          value mx3fmt

              1='from'

              2='to'

              4='from'

              3='to'

          ;

 

     proc format;

          value rgn1fmt

              1='NE'

              2='HA'

              3='LA'

              4='CU'

              5='EG'

          ;

 

     proc format;

          value $rgn2fmt

              'NE'='Nigeria'

              'HA'='Haiti'

              'LA'='Laos'

              'CU'='Cuba'

              'EG'='Egypt'

              'WL'='World'

          ;

%mend mk_formats;

 

 

%macro prepdat3;

 

     data tmp_sum_wtadata(drop= ym);

          set data.sum_wtadata;

 

          if ctry_rgn ne 'WL';

 

          if ym=1;

 

          if year(cal) ge year(&endhist)-4;

 

     data tmpt(rename = (le=tle y=ty)) tmpa(rename = (le=ale yoy=ayoy))

              tmpv(rename = (le=vle y=vy)) tmpo(rename = (le=ole y=oy));

          set tmp_sum_wtadata;

 

          if tvo=1 then

              output tmpt;

 

          if tvo=2 then

              output tmpa;

 

          if tvo=3 then

              output tmpv;

 

          if tvo=4 then

              output tmpo;

 

     proc sort data=tmpt;

          by ctry_rgn descending mx cal;

 

     proc sort data=tmpa;

          by ctry_rgn descending mx cal;

 

     proc sort data=tmpv;

          by ctry_rgn descending mx cal;

 

     data tbl3data(drop=tvo);

          merge tmpa tmpv tmpt;

          by ctry_rgn descending mx cal;

 

     data tbl3data;

          set tbl3data;

 

          if mx=1 then

              mx=4 ;

 

     if mx=2 then

              mx=3;

 

     proc sort data=tbl3data;

          by ctry_rgn descending mx cal_;

 

          /*proc contents;

          proc print;*/

%mend prepdat3;

 

*********************************************************************************************;

*prepdat4 - data for table1;

*********************************************************************************************;

 

%macro mk_table3(argn);

 

     data tmp;

          set tbl3data;

          by ctry_rgn descending mx;

 

          if ctry_rgn=put(&argn,rgn1fmt.);

 

 

 

 

     title “US Imports from Company Defined “||put(ctry_rgn,$rgn2fmt.);

 

 

title “US Exports from Company Defined “||put(ctry_rgn,$rgn2fmt.);

 

     run;

 

%mend mk_table3;

 

%driver;

 

 

1 REPLY 1
Shmuel
Garnet | Level 18

Am I right - you want to create two reports from each of the 5 tables by

splitting observations between the two reports, in equal parts ?

 

Would you like to make the split in the middle of the dataset or 

split it by odd and even occurence in the dataset ?

 

In the first case you need know how many observation are in, divide by 2 then

create reports: (1) where _N_ le result (2) where _N_ ge result

 

In 2nd case you can split by:

    (1) where mod(_N_,2) = 0  (2) where mod(_N_,2) ne 0

 

As about the titles, you anyhow need to addapt the reporting macro to create two reports,

that is: (1) what where to use (2) assign  the proer title according to the where 

 

By the way - why is line   %macro mk_formats;   twice in your code ?

If you run it you might have error messages.

 

 

 

 

 

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
  • 1 reply
  • 699 views
  • 0 likes
  • 2 in conversation