SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 34629: Coming to SAS from SPSS

DetailsOutputDownloadsAboutRate It
These examples appear in Appendix B of The Little SAS Book: A Primer, Fourth Edition.

Before you run the examples, open the zip file under the Downloads tab. Using the list below, create the folders and copy the data files so that the data are available during your SAS session.

Create the folder c:\MyRawData and copy these files to it:

            
   Address.dat          IceCreamSales.dat         Shakespeare.dat      
   Admit.dat            IceCreamSales2.dat        Shoe.dat             
   AllScores.dat        Lengths.dat               Shoesales.dat        
   Artists.dat          Library.dat               South.dat             
   Baseball.dat         LibraryBooks.dat          Speed.dat              
   Basketball.dat       Mag.dat                   Survey.dat             
   Boats2.dat           Mens5000.dat              Temperature.dat      
   Boats.dat            Mountains.dat             Temps.dat             
   Books.dat            Movies.dat                ToadJump.dat         
   Bus.dat              NatPark.Dat               Tomatoes.dat          
   Candy.dat            NewAdmit.dat              Traffic.dat          
   Cars.dat             North.dat                 Train.dat             
   Choc.dat             Olympic1500.dat           Transpos.dat         
   Chocolate.dat        OnionRing.dat             TropicalSales.dat        
   Chocsales.dat        Onions.dat                UsedCars.dat         
   Coffee.dat           OrdersQ3.dat              Walk.dat             
   Criterium.dat        Parks.dat                 WBRK.dat             
   CustAddress.dat      Picbooks.dat              Zoo.dat                
   Disc.dat             Precipitation.dat                                  
   Exercise.dat         President.dat             Bands.csv             
   Flowers.dat          Pumpkin.dat               Bands2.csv             
   Games.dat            Records.dat               Women.csv            
   Garden.dat           Scores.dat                                     
   Home.dat             SeaLife.dat                                     
                                                                       
 
Create the folder c:\MyFiles and copy this file to it: Baseball.xls

Create the folder c:\MyWebLogs and copy this file to it: dogweblogs.txt

Create the folder c:\MyExcelFiles and copy these files to it: Baseball.xls, OnionRing.xls

Create the folder c:\MyData to store files when you run examples

Create the folder c:\MyHTML to store files when you run examples

Create the folder c:\MyHTMLFiles to store files when you run examples

Create the folder c:\MyPDFFiles to store files when you run examples

Create the folder c:\MyRTFFiles to store files when you run examples

Create the folder c:\MySASLib and copy this file to it: TropicalSales.dat


SPSS Program (page 315)

DATA LIST FILE =                
  'c:\MyRawData\Survey.dat'	        
  /Name 1-8 (A) Age 9-10 	          
  Sex 12 Song1 TO Song5 13-22.	       
VARIABLE LABELS	                    
  Song1 'Black Water'	                
  Song2 'Bennie and the Jets'	        
  Song3 'Stayin Alive'	               
  Song4 'Yellow Submarine'	           
  Song5 'Only Time'.	            
VALUE LABELS	                       
  sex 1 'female' 2 'male'.	                   
TITLE 'Music Market Survey'.    
LIST.	                           
FREQUENCIES	                     
  VARIABLES = Song1.	               
CROSSTABS	                          
  /TABLES = Sex BY Song1.      	 
SAVE OUTFILE =	
  'c:\MySPSSDir\survey.sav'.


SAS Program (page 315)

DATA 'c:\MySASLib\survey';
   INFILE 'c:\MyRawData\Survey.dat';
   INPUT Name $ 1-8 Age
      Sex Song1-Song5;
   LABEL Song1 = 'Black Water' 
      Song2 = 'Bennie and the Jets'
      Song3 = 'Stayin Alive'
      Song4 = 'Yellow Submarine'
      Song5 = 'Only Time';
PROC FORMAT;
   VALUE sex 1 = 'female'
          2 = 'male';
TITLE 'Music Market Survey';
PROC PRINT;
PROC FREQ;
   TABLE Song1 Sex * Song1;
   FORMAT Sex Sex.;
RUN;


Program (page 318)

LIBNAME myspss SPSS 'c:\MySPSSDir\survey.por';
* Print the SPSS portable file;
PROC PRINT DATA = myspss.getsurv;
   TITLE 'Music Market Survey';
RUN;
* List the contents of the SPSS portable file;
PROC CONTENTS DATA = myspss.getsurv;
RUN;
* Convert SPSS portable file to SAS data set;
DATA 'c:\MySASLib\sassurvey';
   SET myspss.getsurv;
RUN;


Program (page 320)

* Import an SPSS save file as a permanent SAS data set;
LIBNAME radio 'c:\MySASLib'; 
PROC IMPORT DATAFILE = 	
            'c:\MySPSSDir\survey.sav'			            
            OUT = radio.sassurvey 
            DBMS = SAV 
            REPLACE;
RUN;
* Print the new SAS data set;
PROC PRINT DATA = radio.sassurvey;
   TITLE 'Music Market Survey';
RUN;


First Program (page 321)

* Import an SPSS SAV file as a temporary SAS data set;
PROC IMPORT DATAFILE = 	'c:\MySPSSDir\survey.sav'
		OUT = sassurvey 
            DBMS = SAV 
            REPLACE;
RUN;
Second Program (page 321)
OPTIONS NOFMTERR;
LIBNAME radio 'c:\MySASLib'; 
* Print the SAS data set;
PROC PRINT DATA = radio.sassurvey;
   TITLE 'Music Market Survey';
RUN;


The sample is authored by Lora D. Delwiche and Susan J. Slaughter.
Their book The Little SAS Book: A Primer, Fourth Edition is available for sale in our online bookstore.


These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.