- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a macro variable with few values i want to use this variable to create a data set having these values with the help of infile statement. I have tried but I'm getting some error. Please help me out in this and thank you in advance.
%let X = "AU","US","IND";
Data one;
infile &terr dlm = ",";
input A $ @@;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let X = "AU","US","IND"; /* what for is X defined? It's never used */
Data one;
infile &terr dlm = ","; /* where and how is terr defined? */
input A $ @@;
run;
Please supply:
- the log of your code; use the {i} button for this
- the statement(s) where &terr is defined
- an example of your input file
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sry it is not &terr it is &X
%let X = "AU","US","IND";
Data one;
infile &X dlm = ",";
input A $ @@;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Replace &X with the contents of X, and you will see that it creates invalid code (consult the documentation of the infile statement).
If that are the names of three different infiles, you can concatenate the files by using brackets around the filenames.
But I strongly believe that "AU" (for instance) is not the name of an external (text) file in your current working directory.
Please describe in more detail what you want to do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you trying to get this?
%let X = "AU, US, IND"; Data one; nw = countw(&X); do i = 1 to nw; A = scan(&X,i); output; end; keep A; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Swati24 wrote:
I have a macro variable with few values i want to use this variable to create a data set having these values with the help of infile statement. I have tried but I'm getting some error. Please help me out in this and thank you in advance.
%let X = "AU","US","IND";
Data one;
infile &terr dlm = ",";
input A $ @@;
run;
Look at PROC STREAM. https://documentation.sas.com/?docsetId=proc&docsetTarget=n1sak3n3asxfbqn1aw24lxdvez69.htm&docsetVer...
Or use the "_infile_" trick.
%let X = "AU","US","IND";
data one;
infile cards dsd ;
input @;
_infile_ =symget('x');
length A $8 ;
do until(a=' ');
input A $ @ ;
if not missing(a) then output;
end;
cards;
-- this line is ignored --
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
After cards; nothing will be written
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
run should be there or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Swati24 wrote:
run should be there or not
You include a RUN or QUIT statement to let SAS (and other programmers) know that you have reached the end of a procedure or data step. But a data step that includes in-line data (signaled by the CARDS statement or as it has been renamed DATALINES) ends when the in-line data ends. Any extra RUN statement after that will not have any effect other than confusing some novice programmers into thinking they can insert additional data step statements between the lines of data and the run statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As it is throwing data error Saying
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Quote from myself:
"Please describe in more detail what you want to do."
Little bits and pieces like this
@Swati24 wrote:
As it is throwing data error Saying
NOTE: LOST CARD.84 OPTIONS NONOTES 15A=IND _ERROR_=1 _INFILE_= _N_=1NOTE: SAS went to a new line when INPUT statement reached past the end of a line.NOTE: The data set WORK.ONE has 3 observations and 1 variables.
are not helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let X = "AU","US","IND"; data want; do i=1 to countw(symget('x'),',"'); x=scan(symget('x'),i,',"'); output; end; run;