BookmarkSubscribeRSS Feed
satish78652
Fluorite | Level 6

Hi Mates,

 

I need help from you guys. I want to get the text of word document into SAS datasets by converting the headings in the documents as variables for the SAS datasets.

 

Example of the Word document:

Name:

John

Sex:

Male

Age:

25 years

Address:

#2-3-4-5, 2nd cross,

1st Main, NY

 

Output I need:

obs Name   Sex     Age            Address

01   Jhon     Male  25 Years    #2-3-4-5, 2nd cross,

                                               1st Main, NY

 

Can any one help me to find a solution for this?????

Thank you

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

From Word, File->Save As-> save the file as .txt.  Then write a datastep to read the text file and output to your given requirements:

data want;
  length buff name sex address $2000;
  infile "thetextfile.txt";
  input buff $;
  if buff="Name:" then input name $;
...
run;

The real question is why are you using an output for human review file format such as Word as data.  Return to the source data and go from there, thats really the only "good" way.

satish78652
Fluorite | Level 6

Thank you for the reply. In the programme you provided i need to specify the variables manually, my actual problem is that i am looking for macro which can extract the headings or bookmarks as variables of SAS dataset.

 

Thank you.

Oligolas
Barite | Level 11

Well I sincerely hope you find what you are looking for. Please tell me if you find it.

Not later than yesterday I had to do the same thing.

I copied the Word data to an appropriate text editor, converted the special characters to adequate ones, ensured the proper tab delimitation and missing replacement and imported it as a formatted text file and performed an extensive quality check.

 

I don't know how but hey I think what you want is doable. A *.docx file is nothing else than a zipped XML file. I think it's feasible to hack yourself into it and extract the formatted tables.

 

I wish you big success, here are some starting points: 1   2

 

Cheers

________________________

- Cheers -

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, 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
  • 4 replies
  • 881 views
  • 0 likes
  • 4 in conversation