05-03-2017 09:44 AM
I have a problem. So I wanted to do a macro which imports a txt file into sas. The txt contains random words in one line. So basically I want to do is that put them into one column. My method would do it, but it's keep saying ERROR.
"NOTE: Invalid data for words in line 12 1-4.
12 down, 5
words=. _ERROR_=1 _N_=12" and so on.
Or it just doesn't show any words. Just a '.'
Here is my code:
%macro wordfreq(x); data test.wrd; infile "D:\Munka\&x..txt" DLM=','; input words; run; %mend; %wordfreq(wrd); The txt contains: random, words, coming, up, right, now, here, random, words, here, coming, down, up, word, coming, random, way
Thank you for your help!
ps.: My main tast is to do a freq macro which group the same words and show the frequency of each ones.
05-03-2017 10:00 AM
I think what you want is the @@ modifier on your input statement, as follows:
data want; infile datalines dsd; input words $ @@; datalines; random, words, coming, up, right, now, here, random, words, here, coming, down, up, word, coming, random, way ;
05-03-2017 10:01 AM
I'm not entirely use why you need a Macro program to do this. I think all you need to do is change your INPUT statement and use PROC FREQ.
05-03-2017 10:02 AM
Two things come to mind when looking at your code:
1) Your input statement defines WORD as numeric. Use a dollar sign to indicate a character.
2) Your file seems to have multiple valiues for WORD in a single line. Your code however reads just the first word in every line. Use a double trailing at sign to retain the record in the buffer until all words are collected:
filename t temp; data _null_; file t; put 'random, words, coming, up, right, now, here, random, words, here, coming, down, up, word, coming, random, way'; run; %macro wordfreq(x); data wrd; infile t DLM=','; input words $ @@; run; %mend; %wordfreq(wrd);
(I have put your data into a temp file for easier testing)
Hope this helps,
Need further help from the community? Please ask a new question.