BookmarkSubscribeRSS Feed
Swati24
Obsidian | Level 7

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;

12 REPLIES 12
Kurt_Bremser
Super User
%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
Swati24
Obsidian | Level 7

Sry it is not &terr it is &X

%let X = "AU","US","IND"; 

Data one;
infile &X dlm = ",";
input A $ @@;
run;
Kurt_Bremser
Super User

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.

KachiM
Rhodochrosite | Level 12

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;
Tom
Super User Tom
Super User

@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 --
;
Swati24
Obsidian | Level 7

After cards; nothing will be written

 

Swati24
Obsidian | Level 7

run should be there or not

Tom
Super User Tom
Super User

@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.

Swati24
Obsidian | Level 7

As it is throwing data error Saying

 

NOTE: LOST CARD.
84 OPTIONS NONOTES 15
A=IND _ERROR_=1 _INFILE_= _N_=1
NOTE: 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.
Kurt_Bremser
Super User

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 15
A=IND _ERROR_=1 _INFILE_= _N_=1
NOTE: 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.

Reeza
Super User
Why do you have a macro variable X, but then the macro variable &TERR in the INFILE statement. Where is TERR defined?
Ksharp
Super User
%let X = "AU","US","IND";

data want;
 do i=1 to countw(symget('x'),',"');
  x=scan(symget('x'),i,',"');
  output;
 end;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 2015 views
  • 1 like
  • 6 in conversation