Desktop productivity for business analysts and programmers

Converting from Base SAS

Reply
Frequent Contributor
Posts: 78

Converting from Base SAS

How do I convert this to SAS EG?

004066     DATA _NULL_;                 
004067       SET OUTPUT02.DATA;         
004068       FILE OUTPUTO1 LS=750;              

 

Right now, I have this in SAS EG:

DATA AREALVL;

    SET &NAME..OUTPUT02;

 

                               

 

 

Community Manager
Posts: 3,344

Re: Converting from Base SAS

You're using EG to run this code on Base SAS.  So no code conversion is necessary if everything about the environment is the same.

 

However, if you were using PC SAS and now you are using EG in a distributed environment, your file references and other environment-specific items will need to change.  The details of this conversion are specific to your setup, but you can get oriented by reading this paper about transitioning from PC SAS.

Frequent Contributor
Posts: 78

Re: Converting from Base SAS

Posted in reply to ChrisHemedinger

The problem I am having is that the columns in the output are not in the order they should be even though the PUT statement has not changed from the program that was in Base SAS.

 

When I go to export the AREALVL data set, the columns are not following the PUT statement order for some reason.  This is what it looks like in Base SAS and SAS EG:

 

 IF CIVALLW   IN ("" ".") THEN CIVALLW   = 0; 
 IF CIVPRE    IN ("" ".") THEN CIVPRE    = 0; 
 IF OTHALLW   IN ("" ".") THEN OTHALLW   = 0; 
 IF OTHPRE    IN ("" ".") THEN OTHPRE    = 0; 
 IF EDICNT    IN ("" ".") THEN EDICNT    = 0; 
 IF PPRCNT    IN ("" ".") THEN PPRCNT    = 0; 
 IF ELIGADFM  IN ("" ".") THEN ELIGADFM  = 0; 
 IF ELIGADSM  IN ("" ".") THEN ELIGADSM  = 0; 
 IF ELIGNADF  IN ("" ".") THEN ELIGNADF  = 0; 
 IF ELIGOTHR  IN ("" ".") THEN ELIGOTHR  = 0; 
 IF ADFMCIV   IN ("" ".") THEN ADFMCIV   = 0; 
 IF ADFMMTF   IN ("" ".") THEN ADFMMTF   = 0; 
 IF ADFTCIV   IN ("" ".") THEN ADFTCIV   = 0; 
 IF ADFTMTF   IN ("" ".") THEN ADFTMTF   = 0; 
 IF ADSMCIV   IN ("" ".") THEN ADSMCIV   = 0; 
 IF ADSMMTF   IN ("" ".") THEN ADSMMTF   = 0; 
 IF ADSTCIV   IN ("" ".") THEN ADSTCIV   = 0; 
 IF ADSTMTF   IN ("" ".") THEN ADSTMTF   = 0; 
 IF NADFCIV   IN ("" ".") THEN NADFCIV   = 0; 
 IF NADFMTF   IN ("" ".") THEN NADFMTF   = 0; 
 IF TAMPCIV   IN ("" ".") THEN TAMPCIV   = 0; 
 IF TAMPMTF   IN ("" ".") THEN TAMPMTF   = 0; 
 IF TRSVCIV   IN ("" ".") THEN TRSVCIV   = 0; 

IF TRSVMTF   IN ("" ".") THEN TRSVMTF   = 0;
IF TRSSP     IN ("" ".") THEN TRSSP     = 0;
IF TRSFM     IN ("" ".") THEN TRSFM     = 0;
IF TRRSP     IN ("" ".") THEN TRRSP     = 0;
IF TRRFM     IN ("" ".") THEN TRRFM     = 0;
IF TYA       IN ("" ".") THEN TYA       = 0;
IF TYAPR     IN ("" ".") THEN TYAPR     = 0;
IF CIVAUNET  IN ("" ".") THEN CIVAUNET  = 0;
IF CIVAUTOT  IN ("" ".") THEN CIVAUTOT  = 0;
IF CIVRFNET  IN ("" ".") THEN CIVRFNET  = 0;
IF CIVRFTOT  IN ("" ".") THEN CIVRFTOT  = 0;
IF MTFAUNET  IN ("" ".") THEN MTFAUNET  = 0;
IF MTFAUTOT  IN ("" ".") THEN MTFAUTOT  = 0;
IF MTFRFNET  IN ("" ".") THEN MTFRFNET  = 0;
IF MTFRFTOT  IN ("" ".") THEN MTFRFTOT  = 0;
IF OTHAUNET  IN ("" ".") THEN OTHAUNET  = 0;
IF OTHAUTOT  IN ("" ".") THEN OTHAUTOT  = 0;
IF OTHRFNET  IN ("" ".") THEN OTHRFNET  = 0;
IF OTHRFTOT  IN ("" ".") THEN OTHRFTOT  = 0;
IF CIVINCN   IN ("" ".") THEN CIVINCN   = 0;
IF CIVCN     IN ("" ".") THEN CIVCN     = 0;
IF CIVINPD   IN ("" ".") THEN CIVINPD   = 0;
IF CIVPD     IN ("" ".") THEN CIVPD     = 0;
IF MTFINPD   IN ("" ".") THEN MTFINPD   = 0;

IF MTFPD     IN ("" ".") THEN MTFPD     = 0; 
IF MTFINCN   IN ("" ".") THEN MTFINCN   = 0; 
IF MTFCN     IN ("" ".") THEN MTFCN     = 0; 

 

  IF AREA IN ('' 'UNKNOWN') THEN DO;                        
     AREATYP = 'OUT OF REGION';                             
     MARKET = 'OUT OF REGION';                              
     MKTAREA = 'OUT OF REGION';                             
     AREA = 'OUT OF REGION';                                
     END;                                                   
                                                            
RUN;                                                        
                                                            
PROC SORT DATA=OUTPUT01 OUT=OUTPUT01.DATA;                  
  BY MKTAREA MARKET AREA AREATYP;                           
RUN;                                                        
                                                            
PROC SUMMARY NWAY MISSING DATA=OUTPUT01.DATA;               
  BY MKTAREA MARKET AREA AREATYP;                           
  VAR CIVALLW CIVPRE OTHALLW OTHPRE                         
      EDICNT PPRCNT                                         
      ELIGADFM ELIGADSM ELIGNADF ELIGOTHR                   
      ADFMCIV ADFMMTF ADSMCIV ADSMMTF NADFCIV NADFMTF       
        ADFTCIV ADFTMTF ADSTCIV ADSTMTF TRSSP TRSFM         
        TRRSP TRRFM TYA TYAPR TAMPCIV TAMPMTF TRSVCIV TRSVMTF
      CIVAUNET CIVAUTOT CIVRFNET CIVRFTOT MTFAUNET MTFAUTOT 

         MTFRFNET MTFRFTOT OTHAUNET OTHAUTOT OTHRFNET OTHRFTOT  
       CIVCN CIVINCN CIVINPD CIVPD MTFCN MTFINCN MTFINPD MTFPD; 
 OUTPUT OUT=OUTPUT02.DATA (DROP=_TYPE_ _FREQ_) SUM=;            
                                                                
                                                                
 DATA _NULL_;                                                   
   SET OUTPUT02.DATA;                                           
   FILE OUTPUTO1 LS=750;                                        
                                                                
   PUT MKTAREA     +(-1)'$'                                     
       MARKET      +(-1)'$'                                     
       AREA        +(-1)'$'                                     
       AREATYP     +(-1)'$'                                     
       CIVALLW     +(-1)'$'                                     
       CIVPRE      +(-1)'$'                                     
       OTHALLW     +(-1)'$'                                     
       OTHPRE      +(-1)'$'                                     
       CIVINCN     +(-1)'$'                                     
       CIVCN       +(-1)'$'                                     
       CIVINPD     +(-1)'$'                                     
       CIVPD       +(-1)'$'                                     
       MTFINCN     +(-1)'$'                                     
       MTFCN       +(-1)'$'                                     
       MTFINPD     +(-1)'$'                                     
       MTFPD       +(-1)'$'                                     
       EDICNT      +(-1)'$'                                     

 

 

I think there might be an issue with the PUT statement because the output is not coming in at that order in SAS EG.

 


                                              

Super User
Posts: 9,548

Re: Converting from Base SAS

The data _null_ step will stay a data _null_ step, but the file name in the preceding filename statement will probably have to change.

 

So your two pieces of code do not match.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 78

Re: Converting from Base SAS

Posted in reply to KurtBremser

It outputs to AREALVL, but the order of my columns in the output differ.  I put an example in response to the other responder.

Super User
Super User
Posts: 7,844

Re: Converting from Base SAS


@essdee wrote:

It outputs to AREALVL, but the order of my columns in the output differ.  I put an example in response to the other responder.


Are you using data to generate code?  If the order has changed the perhaps the data is sorted differently.

Could be caused by a difference in option settings.  For example if you have VALIDVARNAME=UPCASE option set then the names of variables will be in all uppercase, but if you use VALIDVARNAME=V7 they might be in mixed case.  So if you sort by those names the order would be different.

Frequent Contributor
Posts: 78

Re: Converting from Base SAS

Basically, it looks like I need to change the variables in the VAR statement to match the order of the PUT statement. This will show in order once it's output.  Not sure why that is in SAS EG, but that seems to be the fix because I have another program and it's in order because the VAR list is in the same order as the PUT list.

 

 

2857 PROC SUMMARY NWAY MISSING DATA=&NAME..OUTPUT01;

2858 BY NETAREA AREA AREATYP;

2859 VAR CIVALLW CIVPRE OTHALLW OTHPRE

2860 EDICNT PPRCNT

2861 ELIGADFM ELIGADSM ELIGNADF ELIGOTHR

2862 ADFMCIV ADFMMTF ADSMCIV ADSMMTF NADFCIV NADFMTF

2863 ADFTCIV ADFTMTF ADSTCIV ADSTMTF TRSSP TRSFM

2864 TRRSP TRRFM TYA TYAPR TAMPCIV TAMPMTF TRSVCIV TRSVMTF

2865 CIVAUNET CIVAUTOT CIVRFNET CIVRFTOT MTFAUNET MTFAUTOT

2866 MTFRFNET MTFRFTOT OTHAUNET OTHAUTOT OTHRFNET OTHRFTOT

2867 CIVCN CIVINCN CIVINPD CIVPD MTFCN MTFINCN MTFINPD MTFPD;

2868 OUTPUT OUT=&NAME..OUTPUT02 (DROP=_TYPE_ _FREQ_) SUM=;

2869

2870

2871

NOTE: There were 550 observations read from the data set THRUINC3.OUTPUT01.

NOTE: The data set THRUINC3.OUTPUT02 has 97 observations and 53 variables.

NOTE: PROCEDURE SUMMARY used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 

75 The SAS System 10:15 Thursday, April 19, 2018

2871 ! DATA AREALVL;

2872 SET &NAME..OUTPUT02;

2873

2874 PUT NETAREA +(-1)'$'

2875 AREA +(-1)'$'

2876 AREATYP +(-1)'$'

2877 CIVALLW +(-1)'$'

2878 CIVPRE +(-1)'$'

2879 OTHALLW +(-1)'$'

2880 OTHPRE +(-1)'$'

2881 CIVINCN +(-1)'$'

2882 CIVCN +(-1)'$'

2883 CIVINPD +(-1)'$'

2884 CIVPD +(-1)'$'

2885 MTFINCN +(-1)'$'

2886 MTFCN +(-1)'$'

2887 MTFINPD +(-1)'$'

2888 MTFPD +(-1)'$'

2889 EDICNT +(-1)'$'

2890 PPRCNT +(-1)'$'

2891 CIVRFNET +(-1)'$'

2892 CIVRFTOT +(-1)'$'

2893 MTFRFNET +(-1)'$'

2894 MTFRFTOT +(-1)'$'

2895 OTHRFNET +(-1)'$'

2896 OTHRFTOT +(-1)'$'

2897 CIVAUNET +(-1)'$'

2898 CIVAUTOT +(-1)'$'

2899 MTFAUNET +(-1)'$'

2900 MTFAUTOT +(-1)'$'

2901 OTHAUNET +(-1)'$'

2902 OTHAUTOT +(-1)'$'

2903 ELIGADSM +(-1)'$'

2904 ELIGADFM +(-1)'$'

2905 ELIGNADF +(-1)'$'

2906 ELIGOTHR +(-1)'$'

2907 ADSMCIV +(-1)'$'

2908 ADSMMTF +(-1)'$'

2909 ADSTCIV +(-1)'$'

2910 ADSTMTF +(-1)'$'

2911 ADFMCIV +(-1)'$'

2912 ADFMMTF +(-1)'$'

2913 ADFTCIV +(-1)'$'

2914 ADFTMTF +(-1)'$'

2915 NADFCIV +(-1)'$'

2916 NADFMTF +(-1)'$'

2917 TAMPCIV +(-1)'$'

2918 TAMPMTF +(-1)'$'

2919 TRSVCIV +(-1)'$'

2920 TRSVMTF +(-1)'$'

2921 TRRSP +(-1)'$'

2922 TRRFM +(-1)'$'

2923 TRSSP +(-1)'$'

2924 TRSFM +(-1)'$'

2925 TYA +(-1)'$'

2926 TYAPR +(-1)'$';

2927 RUN;

PROC Star
Posts: 8,094

Re: Converting from Base SAS

In your latest example you're not creating an external file as you didn't include a FILE statement. As such, the put statement is simply writing the values to your log. Your datastep is simply creating a copy of THRUINC3.OUTPUT02 and writing a bunch of data to your log.

 

In short, the PUT statements don't have any effect on the creation of the SAS dataset work.AREALVL

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 9,548

Re: Converting from Base SAS

The order in the external output file is determined solely by the PUT statement. As long as that is the same, the order will stay the same.

And the order of variables within an observation is mostly irrelevant, as variables are adressed by name and not position.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 8 replies
  • 144 views
  • 0 likes
  • 5 in conversation