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;
%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:
Sry it is not &terr it is &X
%let X = "AU","US","IND";
Data one;
infile &X dlm = ",";
input A $ @@;
run;
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.
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;
@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 --
;
After cards; nothing will be written
run should be there or not
@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.
As it is throwing data error Saying
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.
%let X = "AU","US","IND"; data want; do i=1 to countw(symget('x'),',"'); x=scan(symget('x'),i,',"'); output; end; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.