BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Amy0223
Quartz | Level 8

Hi, I'm struggling with this question below. Your input is much appreciated! 

data all;
infile ‘ubaacs.survey.tariff ’;
input type $1. @;
if type=’m’ then do;
   input nreps 2. id $2.;
   do i=1 to nreps;
       input uear rate;
       output;
    end;
    end;
run;
  1. What variables will be in dataset all?   
    I think they are type, nreps, id, uear, rate. Please correct me if I'm wrong.
  2. Suppose the raw dataset identified by the infile statement looked like this:

    m 3us

    87 5.4

    88 5.15

    89 5.0

    i 1us

    9.7 11.2

    m 2it

    88 6.0

    89 5.8

    What will dataset all look like???

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You can avoid having to access an external file by using inline data with the datalines file reference and datalines statement:

data all;
infile datalines;
input type $1. @;
if type = 'm' then do;
  input nreps 2. id $2.;
  do i = 1 to nreps;
    input uear rate;
    output;
  end;
end;
datalines;
m 3us
87 5.4
88 5.15
89 5.0
i 1us
9.7 11.2
m 2it
88 6.0
89 5.8
;

Note:

  • I corrected the artifacts of using a word processor for code
  • I did some visual formatting on the code to make it readable
  • I used the "little running man" button to open a window fror posting SAS code, so code is preserved as-is

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

You could actually run the code, and find out the answer that way.

--
Paige Miller
Amy0223
Quartz | Level 8
Thank you. I'm not really sure how to infile this raw data in Data all in order to run the codes.
PaigeMiller
Diamond | Level 26

You create a text file, with the name given in the infile statement, and then you run the code.

 

By the way, it seems as if the code you showed was perhaps pasted into here from Microsoft Word, in which case all of the quotes need to be replaced with "un-curly" quotes that SAS will recognize (SAS doesn't recognize the "curly" quotes).

--
Paige Miller
Amy0223
Quartz | Level 8
Thank you very much for the information. I will pay attention to it.
Shmuel
Garnet | Level 18

Let's do the computer work:

the input              computer work
=======        ==========================
m 3us             type='m' and nreps=3 id='us'
87 5.4            rep1 ==> uear =88  rate=5.4
88 5.15           rep2 ==> complete it by yourself
89 5.0            rep3 ==>
i 1us             type ne 'm' ==> skip it
9.7 11.2          type ne 'm' ==> skip it
m 2it             type = 'm' and nreps=2 id='it'  
88 6.0            rep1 ==>
89 5.8            rep2 ==>
Amy0223
Quartz | Level 8
Thank you very much for helping me understand this problem. I greatly appreciate it!
ChrisNZ
Tourmaline | Level 20

What variables are in the table is determined at compile time.

The data has nothing to do with it.

 

Hint: you forgot one variable.

 

 

Kurt_Bremser
Super User

You can avoid having to access an external file by using inline data with the datalines file reference and datalines statement:

data all;
infile datalines;
input type $1. @;
if type = 'm' then do;
  input nreps 2. id $2.;
  do i = 1 to nreps;
    input uear rate;
    output;
  end;
end;
datalines;
m 3us
87 5.4
88 5.15
89 5.0
i 1us
9.7 11.2
m 2it
88 6.0
89 5.8
;

Note:

  • I corrected the artifacts of using a word processor for code
  • I did some visual formatting on the code to make it readable
  • I used the "little running man" button to open a window fror posting SAS code, so code is preserved as-is
Amy0223
Quartz | Level 8
I was having a lot of errors when running the codes but now I understand why. You are amazing! Thank you very much for taking your precious time to help me. I greatly appreciate it!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 9 replies
  • 850 views
  • 3 likes
  • 5 in conversation