BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MichaelPearce
Obsidian | Level 7

Hi,

I am trying to read in data from the paste buffer that contains tabs, e.g. from Excel.

The PasteBuffer_c class replaces 1 tab with 6 spaces.

Filename Clippy clipbrd, also replaces 1 tab with 6 spaces, it also fails to work at all if you try and set lrecl.

There was an option to try dde 'clipboard' but also no luck.

The main solution is to add up the 6 spaces and call it a break, but making a tab delimited file from SAS adds a single space for an empty text field, Excel will maintain that space but  the user can remove it by clearing the cell or if the user creates their own sheet that space will not exist at all.

This means in a wide, sparsely populated sheet you get 6 spaces for a tab and 1 or 0 spaces for the cell contents, 6 empty cells will either get you another break point or not.

Is there an option to read the paste buffer and keep the tabs, can this option also read more than 256 chars wide?

An example: This creates a string of 4 column names, separated by tabs, SAS knows that tabs are there, you can paste the created string and it keeps the tabs.

You just cant seem to read it in SAS and keep the tabs.

data bob;

  format text $char100.;

  text = "Study"|| '09'x ||"Appendix"|| '09'x ||"Number"|| '09'x ||"Section";

  do x = 1 to 10;

    n = rank(substr(text,x,1));

    put x= n=;

  end;

run;

filename clippy clipbrd;

data _null_;

  set bob;

  file clippy;

  put text;

run;

data _null_;

  infile clippy;

  input;

  put _infile_;

  do x = 1 to 10;

    n = rank(substr(_infile_,x,1));

    put x= n=;

  end;

run;

filename clippy;

* Log;

3    data bob;

4      format text $char100.;

5      text = "Study"|| '09'x ||"Appendix"|| '09'x ||"Number"|| '09'x ||"Section";

6

7      do x = 1 to 10;

8        n = rank(substr(text,x,1));

9        put x= n=;

10     end;

11   run;

x=1 n=83

x=2 n=116

x=3 n=117

x=4 n=100

x=5 n=121

x=6 n=9  Smiley Happy

x=7 n=65

x=8 n=112

x=9 n=112

x=10 n=101

NOTE: The data set WORK.BOB has 1 observations and 3 variables.

NOTE: DATA statement used (Total process time):

      real time           1.36 seconds

      cpu time            0.04 seconds

12

13   filename clippy clipbrd;

14

15   data _null_;

16     set bob;

17     file clippy;

18

19     put text;

20   run;

NOTE: The file CLIPPY is:

      (no system-specific pathname available),

      (no system-specific file attributes available)

NOTE: 1 record was written to the file CLIPPY.

      The minimum record length was 29.

      The maximum record length was 29.

NOTE: There were 1 observations read from the data set WORK.BOB.

NOTE: DATA statement used (Total process time):

      real time           0.05 seconds

      cpu time            0.01 seconds

21

22   data _null_;

23     infile clippy;

24     input;

25

26     put _infile_;

27

28     do x = 1 to 10;

29       n = rank(substr(_infile_,x,1));

30       put x= n=;

31     end;

32   run;

NOTE: The infile CLIPPY is:

      (no system-specific pathname available),

      (no system-specific file attributes available)

Study      Appendix      Number      Section

x=1 n=83

x=2 n=116

x=3 n=117

x=4 n=100

x=5 n=121

x=6 n=32  Smiley Sad

x=7 n=32

x=8 n=32

x=9 n=32

x=10 n=32

NOTE: 1 record was read from the infile CLIPPY.

      The minimum record length was 44.

      The maximum record length was 44.

NOTE: DATA statement used (Total process time):

      real time           0.03 seconds

      cpu time            0.03 seconds

33

34   filename clippy;

NOTE: Fileref CLIPPY has been deassigned.

1 ACCEPTED SOLUTION

Accepted Solutions
MichaelPearce
Obsidian | Level 7

Ah i have found a solution.

dm "whostedit; EDCMD paste; file 'u:\pasteTest.txt'; close";

It flashes up an editor screen but you get the text and the tabs.

View solution in original post

3 REPLIES 3
Ksharp
Super User

infile clippy lrecl=2000 ;

or

option lrecl=2000;  ?

Ksharp

MichaelPearce
Obsidian | Level 7

Hi Ksharp,

Unfortunately I have tried these before, the options setting is ignored and the direct lrecl just causes the step to seize up, I had to break the data step.

It also does not help with retaining the tabs.

I am wondering if this is possible at all.

Michael.

MichaelPearce
Obsidian | Level 7

Ah i have found a solution.

dm "whostedit; EDCMD paste; file 'u:\pasteTest.txt'; close";

It flashes up an editor screen but you get the text and the tabs.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1177 views
  • 0 likes
  • 2 in conversation