BookmarkSubscribeRSS Feed
Anandkvn
Lapis Lazuli | Level 10
data a;
infile "/home/u35263349/if.txt";
input name$ city$ ;
if city='hyderabad' ; run;

1.which statement works  if statetment or where statement in infile statement read the external source data

please find below attachment txt.file

5 REPLIES 5
ballardw
Super User

If you run this code:

 

data a;
infile "/home/u35263349/if.txt";
input name$ city$ ;
run;

You will see that the value in the data is read as "hyderaba". The length is 8 characters because when you  use Input city $; SAS defaults to reading 8 characters. You need to provide an informat longer than 8 OR tell SAS the variable should be longer. So you did not have the value long enough to match your If condition.

 

 

This uses an informat to read City as a 10 character variable:

 

data a;
infile "/home/u35263349/if.txt";
input name$ city :$10. ;
run;

This sets the length of Name and City to 10 characters when read:

data a;
infile "/home/u35263349/if.txt";
length name city $10;
input name$ city $ ;
run;

 

 

Astounding
Opal | Level 21
You need IF, not WHERE.
The IF statement can be used by any DATA step.
The WHERE statement requires that the incoming data is already a SAS data set. Since your source of incoming data is text and not a SAS data set, you cannot use WHERE.
Anandkvn
Lapis Lazuli | Level 10

which statement works in infile statement IF or where

 

Astounding
Opal | Level 21
IF.
Not WHERE.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 261 views
  • 0 likes
  • 4 in conversation