I'm a coder. Welcome to my blog. Here are some of the records on my job.

Categories

Removing unwanted characters from a text file using SAS

I am trying to change the delimiter from comma to pipe in a text file using SAS. The data in the input file looks like-

Site,Variable,20151120010000,5.82,1,1,Project|Code|comment
Site,Variable,20151120020000,5.82,1,1,Project|Code|comment
Site,Variable,20151120030000,5.81,1,1,Project|Code|comment, out of service

I want to change the commas (delimiter) to pipe but if there is a comma (for example in the last line), I don't want to change it to pipe. Basically Project|Code|comment, out of service is one column. I am using the code below (as suggested by a stack overflow member)-

Site|Variable|20151120010000|5.82|1|1|Project|Code|comment
Site|Variable|20151120020000|5.82|1|1|Project|Code|comment
Site|Variable|20151120030000|5.81|1|1|Project|Code|comment,out of service

This might be pretty easy but I am just starting to learn SAS. Any help is greatly appreciated.

Just read the file as a series of text fields and re-write it using a different delimiter. Your problem is that the first few fields are comma delimited and the last two are pipe delimited. It looks like you have three fields but that the first field is 7 comma delimited values. So read the last two columns using ('|') as the delimiter and the first 7 using both pipe and comma ('|,') as the delimiter. Then re-write it using another the delimiter. You will need to make two filerefs to allow it be processed using different delimiters.

Related Articles

I have a large number of files containing data I am trying to process using a Python script. The files are in an unknown encoding, and if I open them in Notepad++ they contain numerical data separated by a load of 'null' characters (represented as NU

I've a fixed width text file so it contains leading zeros and spaces and I need to remove carriage return and line feed characters from the file. Could you please let me know how can I do this using batch script? Input: ABCDEF GHIJK0000ADS ABCDEF GHI

I don't have any scripting experience but I've been asked to create a script to automatically download log files from a storage array controller for daily archiving. Due to the limitations of the storage vendor's CLI, it looks like the most straightf

I'm trying to get about 200 letters/chars (including spaces) from a external text file. I've got the code to display the text i'll include that but to get certain letters i've got no idea. Once again i'm not talking about line's i really mean letters

This continues on from a previous question I have asked actually. I am desperate to find a way to remove the trailing blank lines from text files when generated from an excel file to which I have been unsuccessful so far. I have found the below code

I have a bunch of Arabic, English, Russian files which are encoded in utf-8. Trying to process these files using a Perl script, I get this error: Malformed UTF-8 character (fatal) Manually checking the content of these files, I found some strange cha

This question already has an answer here: How to check if a string contains an element from a list in Python 6 answers I presently have code that deletes all lines from a text file that contain one specific string. Here it is: import os with open(r"o

I am trying to create genetic signatures. I have a textfile full of DNA sequences. I want to read in each line from the text file. Then add 4mers which are 4 bases into a dictionary. For example: Sample sequence ATGATATATCTATCAT What I want to add is

I'm in the process of trying to read different lines from a text file. Current i have a program that can read the follow type of line from a text file if it follows this format: 6361550850261,SHOWALL APN="3" IGF=15 VOW=117 VWD=12 [+][+]52 Using

I have a bash script that runs and outputs to a text file however the colour codes it uses are also included what i'd like to know is how to remove them from the file, ie ^[[38;1;32mHello^[[39m ^[[38;1;31mUser^[[39m so I just want to be left with Hel

I want to read some xml files. when i am opening these files with notepad/wordpad/MS Word or any Browser, it is opening in its original form.But when i tried to execute it with MS DOS, an invisible chacter like "∩╗┐" is seen. I think '∩╗┐' is cr

Let's say I have a text file like this This is a text file which contains some numbers. So I want to use fseek and fread to read some parts of the text file. For example, from position 0 to 13, I'll get "This is a text". Then from position 14 to

I am working with server who's configurations are as: RAM - 56GB Processor - 2.6 GHz x 16 cores How to do parallel processing using shell? How to utilize all the cores of processor? I have to load data from text file which contains millions of entrie