sas cdm training | online sas cdm training | sas cdm online | sas cdm classes | sas cdm course
Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a...
-
Upload
tamara-hiley -
Category
Documents
-
view
218 -
download
5
Transcript of Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a...
![Page 1: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/1.jpg)
Next Presentation:
Presenter: Arthur Tabachneck
Copy and Paste from Word or Excel to SAS
Art holds a PhD from Michigan State University, has been a SAS user since 1974, is president of the Toronto Area SAS Society and has received such recognitions as the SAS Customer Value Award (2009), SAS-L Hall of Fame (2011), SAS Circle of Excellence (2012) and, in 2013, was recognized as being the first SAS Discussion Forum participant to be awarded more than 10,000 points
![Page 2: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/2.jpg)
Copy and Paste from Word or Excel to SAS
Arthur TabachneckThornhill, ON
CanadaMatt Kastin
Penn Valley, PA
![Page 3: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/3.jpg)
Suppose you have data in an Excel workbook
![Page 4: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/4.jpg)
or a table in a Word Document
![Page 5: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/5.jpg)
and you had a one-time needto import the data into a SAS dataset
![Page 6: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/6.jpg)
you have SAS/Access interface to PC files
you don't have a 32/64 bit compatibility issue
and
then you could do it using PROC IMPORT:
proc import out= work.want datafile= "c:\orsales.xlsx" dbms=xlsx replace;run;
if the data are in an Excel workbook andyour SAS version supports Excel 2010 and
![Page 7: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/7.jpg)
your SAS version doesn't support Excel 2010
you don't have SAS/Access Interface to PC files
but, what if:
you keep running into 32/64 bit compatibility issues
and/or
and/or
you need more control over formats, informats or variable names
and/or
the table is in something other than Excel (e.g., Microsoft Word or a web page)
and/or
![Page 8: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/8.jpg)
a simple solution?
a datastep that uses the clipboard access method
gives you total control over all formats and informats
![Page 9: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/9.jpg)
if only if it worked that way, but ..
you can't include notab and lrecl options with the method
won't work if any records have more than 256 characters
will fail if there are any missing cells in the data
![Page 10: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/10.jpg)
but the Clipboard Access Method will work as follows:
![Page 11: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/11.jpg)
How it worksOpen the workbook in Excel1
Press Ctrl-A, then press Ctrl-C2
selects all of the workbook's cells
copies the selected cells to your computer's clipboard
![Page 12: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/12.jpg)
thenRun a datastep in SAS3
filename clippy clipbrd;data orsales_short; attrib Quarter label='Quarter' length=8 informat = yyq6. format=yyq6. Product_Group label='Group' length=$ 25 informat= $25. format=$25. Quantity label='Number of Items' length=8 informat=6. format= 6. Profit label='Profit in USD' length=8 informat=12. format=12.2 Field163 label='Short' length=$ 163 informat=$163. format= $163.; infile clippy missover firstobs=2; input;_infile_ = transtrn( trim( _infile_ ) , ' ' , '09'x ); quarter = input( scan( _infile_ , 1 , '09'x ,'m') , yyq6. ) ; product_group = scan( _infile_ , 2 , '09'x ,'m') ; quantity = input( scan( _infile_ , 3 , '09'x ,'m') , 6. ) ; profit = input( scan( _infile_ , 4 , '09'x ,'m') , 12. ) ; field163 = scan( _infile_ , 5 , '09'x ,'m') ;run;filename clippy clear;
![Page 13: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/13.jpg)
Open the Word file1
Click on the table move handle (i.e., ) 2
Press Ctrl-C3
Works for tables copied from either Word or Excel
selects all of the table's cells
copies the selected cells to your computer's clipboard
![Page 14: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/14.jpg)
Works for tables copied from either Word or Excelthen just run the same SAS code
![Page 15: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/15.jpg)
won't work if any record contains more than 256 characters
Works for tables copied from either Word or Excel
one alternative for longer records, but only for tables copied from Excel and only on systems that can use DDE:
filename clippy dde 'clipboard';data orsales; infile clippy lrecl=400 dsd notab missover dlm='09'x firstobs=2; informat long_field $char327.; informat quarter yyq6.; format quarter YYQ6.; informat product_group $char24.; input quarter product_group quantity profit long_field;run;filename clippy clear;
![Page 16: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/16.jpg)
data want; attrib _inline_ length = $ 32767 Quarter label = 'Quarter' length = 8 informat = yyq6. format = yyq6. Product_Group label = 'Product Group' length = $ 24 informat = $24. format = $24. Quantity label = 'Number of Items' length = 8 informat = 6. format = 6. Profit label = 'Profit in USD' length = 8 informat = 12. format = 12.2 field163 label = 'Short Field' length = $ 163 informat = $163. format = $163. ; keep quarter product_group quantity profit field163; rc = filename( 'clippy' , ' ' , 'clipbrd' ); if ( rc ne 0 ) then link err; fid = fopen( 'clippy' , 's' , 32767 , 'V' ); if ( fid eq 0 ) then link err;
A method that works with both Word and Excel, on all systems, and for records with more than 256 characters
do _n_=1 by 1 while( fread( fid ) = 0 ); rc = fget( fid , _inline_ , 32767 ); _inline_ = transtrn( trim( _inline_ ) , ' ' , '09'x ); if _n_=1 then continue; quarter = input( scan( _inline_ , 1 , '09'x ) , yyq6.,'m') ; product_group = scan( _inline_ , 2 , '09'x,'m' ) ; quantity= input( scan( _inline_ , 3 , '09'x ) , 6.,'m' ) ; profit = input( scan( _inline_ , 4 , '09'x ) , 12.,'m' ) ; field163= scan( _inline_ , 5 , '09'x,'m' ) ; output; end; rc = fclose( fid ); rc = filename( 'clippy' ); stop; err: do; m = sysmsg(); put m; stop; end;run;
![Page 17: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/17.jpg)
three methods were presented for copying and pasting from Excel workbooks and Word tables
only one method, the Clipboard Access Method using functions, worked in all cases:
Summary
with both Excel and Word
with record lengths greater than 256 characters
without being operating system specificwith various combinations of missing data
![Page 18: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/18.jpg)
Questions?
![Page 19: Next Presentation: Presenter: Arthur Tabachneck Copy and Paste from Word or Excel to SAS Art holds a PhD from Michigan State University, has been a SAS.](https://reader030.fdocuments.in/reader030/viewer/2022032517/56649ca55503460f9496766e/html5/thumbnails/19.jpg)
Your comments and questions
are valued and encouragedContact the Authors
Arthur Tabachneck, Ph.D.Vice President, The CatalogThornhill, [email protected]
Matt KastinI-Behavior, Inc.Penn Valley, [email protected]