BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
turcay
Lapis Lazuli | Level 10

Hello everyone,

 

I found a SAS document related to VIEW then I executed in my SAS EG locale. I think It needs to be 5 rows instead of 4 rows but I couldn’t see the the row which begins with frisbee. On the other hand, my another question is how to take student.txt file as following image, how should I separate it when import to EG. Does anyone here can show me with screenshot ? If you show me over student.txt file so much the better.

 

libname myv9lib 'C:\Try';
filename student 'C:\Try\student.txt';
data myv9lib.class(keep=name major credits)
   myv9lib.problems(keep=code date) / view=myv9lib.class;
infile student;
   input name $ 1-10 major $ 12-14 credits 16-18;
select;
when (name=' ' or major=' ' or credits=.)
         do code=01;
            date=datetime();
            output myv9lib.problems;
         end; 
when (0<credits<90)
         do code=02;
            date=datetime();
            output myv9lib.problems;
         end; 
otherwise
       output myv9lib.class;
   end;
run; 
proc print data=myv9lib.class;
run;  

proc print data=myv9lib.problems;
   format date datetime18.;
run;

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a001278887.htm  

student.png

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
bharathkumar
Fluorite | Level 6

Hi,

 

Your every thing perfect except "Missover" option missed in your Infile statement.

 

Try It... I got the results as you expected.

 

First Question:

 

data myv9lib.class1(keep=name major credits)
   myv9lib.problems1(keep=code date) / view=myv9lib.class1;
infile student missover;
   input name $ 1-10 major $ 12-14 credits 16-18;
select;
when (name=' ' or major=' ' or credits=.)
         do code=01;
            date=datetime();
            output myv9lib.problems1;
         end; 
when (0<credits<90)
         do code=02;
            date=datetime();
            output myv9lib.problems1;
         end; 
otherwise
       output myv9lib.class1;
   end;
run; 
proc print data=myv9lib.class1;
run;  

proc print data=myv9lib.problems1;
   format date datetime18.;
run;

 

Second Question:

 

data class(keep=name major credits);
infile student missover;
   input name $ 1-10 major $ 12-14 credits 16-18;
run; 

Thanks & Regards,

Bharath

View solution in original post

8 REPLIES 8
bharathkumar
Fluorite | Level 6

Hi,

 

Your every thing perfect except "Missover" option missed in your Infile statement.

 

Try It... I got the results as you expected.

 

First Question:

 

data myv9lib.class1(keep=name major credits)
   myv9lib.problems1(keep=code date) / view=myv9lib.class1;
infile student missover;
   input name $ 1-10 major $ 12-14 credits 16-18;
select;
when (name=' ' or major=' ' or credits=.)
         do code=01;
            date=datetime();
            output myv9lib.problems1;
         end; 
when (0<credits<90)
         do code=02;
            date=datetime();
            output myv9lib.problems1;
         end; 
otherwise
       output myv9lib.class1;
   end;
run; 
proc print data=myv9lib.class1;
run;  

proc print data=myv9lib.problems1;
   format date datetime18.;
run;

 

Second Question:

 

data class(keep=name major credits);
infile student missover;
   input name $ 1-10 major $ 12-14 credits 16-18;
run; 

Thanks & Regards,

Bharath

turcay
Lapis Lazuli | Level 10

Hello ,

 

Thank you for your help. About my second question, I have to say that, I want to see an image while we import the file from .txt to EG to understand better.I shared a  image as below. I’m not sure what should I do in the following image to get the data set as my previous message's image.

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a002645812.htm

 

SecondQuestion.png

 

About the MISSOVER option, I found a website link. Actually, I nearly understood the option but by default how data reads to raw data from .txt ? How did the following output happen? In spite of following writing I couldn’t properly get it.

 

The DATA step reads the first value (22). Because the value is shorter than the 5 characters expected by the informat,(This part is ok.) the DATA step attempts to finish filling the value with the next record (333).(Why 333 ??? It is also shorter than the 5 characters )This value is entered into the PDV and becomes the value of the TestNumber variable for the first observation.

 

How.png

 

 

Thank you.

Reeza
Super User
Based on the code, you're not dealing with a delimited file, you have a fixed file. Change it from delimited to fixed columns.
turcay
Lapis Lazuli | Level 10

Hello @Reeza,

 

Happy new year to you. I've already tried fixed selection but I couldn't get it.I put a image as below. What should I write now ?  It is not necessary but I just want to learn it. Can you lead me over the image, please ?

 

Fixed.png

 

Thank you.

Reeza
Super User
Well for starters your record length is 20, and your lines are 18, so try changing that.
turcay
Lapis Lazuli | Level 10

Hello @Reeza,

I've actually tried 18 also I put a image as below it includes the screen after I wrote 18 in "Fixed Colum" textbox. Do you have a chance to try the srudent.txt ? But it is not necessarily .Thanks though.

 

18.png

Patrick
Opal | Level 21

The columns are of fixed length but they are not all of the same length so you can't just set a value of 18 or 20.

 

As shown below the EG import wizard lets you set different lengths simply by clicking on the right position in the preview grid. This will result in the correct SAS code being generated. See example below

Capture.PNG

turcay
Lapis Lazuli | Level 10

Hello @Patrick,

 

When I selected the "Fixed Colum" radio button last time "Record Length" was enable. Now the "Record Length" is unable. I don't understand the reason.  Thank you for your help.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 8 replies
  • 1775 views
  • 2 likes
  • 4 in conversation