Hi all,
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.
The 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. 🙂
If it's all separated by commas have you tried using a trailing @@?
Input word $ @@;
If it's all separated by commas have you tried using a trailing @@?
Input word $ @@;
Thank you all for your answer (sorry for this late reply), almost every answer was correct. Thank you again! 🙂 😉
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
;
Hi:
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.
cynthia
Since Cynthia is on here answering questions, I think I'll just get started on my actual job... 😉
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,
- Jan.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.