BookmarkSubscribeRSS Feed
Angel24
Calcite | Level 5

Hi All,

 

I need your help generating variables in SAS. Below is an example of the data which I have in a txt format:

 

Random Data
Random Data
Random Data
Include... ABC
Include... DEF
Include... GHI
Include... JKL

 

123456789123
ABC      ".."  [..]  12  34
DEF      ".."  [..]  56  37
JKL       ".."  [..]  64  73
23455122467
ABC       ".."  [..]  67 43
GHI       ".."  [..]  12 46
JKL       ".."  [..]  87 56
XYZ      ".."  [..]  45 78
56745123446
ABC      ".."  [..]  78 45
DEF      ".."  [..]  12 54
STU      ".."  [..]  32 82
LMN      ".."  [..]  45 36

To be considered:
XYZ
STU
LMN

 

Random Data

 

I want the output in the below format:

Column1ABC_1ABC_2DEF_1DEF_2GHI_1GHI_2JKL_1JKL_2XYZ_1XYZ_2STU_1STU_2LMN_1LMN_2
12345678912312345637  6473      
234551224676743  124687564578    
567451234478451254      32824536

 

Basically, I want to extract the strings after the word "include" and also the strings below "To be considered:" from the txt file and make them column headers followed by _1 and _2 and allocate the values accordingly as shown above in the output. 

 

Any help will be greatly appreciated. Thanks!

 

2 REPLIES 2
Oligolas
Barite | Level 11

Hi,

 

I'd try first to import the *.txt file into a dataset to see if I could use the data structure to create the output I want

If this is not feasible I think I'd import it as bulk in a first step, use regular expressions or text analysis function (index, findw) in a second step to extract the data I need and finally create the output in a third step.

Since this is mainly data triggered you need to know what the data exactly looks like and if the data structure may change in future (maxim 3)

 

________________________

- Cheers -

PaigeMiller
Diamond | Level 26

What is the reason why you want the output in this specific format? Are you going to be producing a report that looks like what you have shown? Or do you need a SAS data set that looks like what you have shown for additional analyses? (If so, what additional analyses?)

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 488 views
  • 0 likes
  • 3 in conversation