BookmarkSubscribeRSS Feed
kerikae1
Calcite | Level 5

 

Hi I am running this code but in the lines where I am ask to Replace the texts I can't seems to get it.....Not sure If i'm doing the right thing Just need some assistance in getting this code done ASAP!! Any help is appreciated  

 

DATA WORK.BAKERYSALES    ;

 INFILE '/home/emilymoore20/EPG194/output/myTestFolder/BSA570v4_Week4_assignment_data.txt' DELIMITER = '|' MISSOVER DSD LRECL=32767 FIRSTOBS=2 ;

 /* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: INFORMAT statements do what? */

 INFORMAT strDate $30. ;

 INFORMAT product best32. ;

 INFORMAT sales nlnum32. ;

 /* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: FORMAT statements do what? */

 FORMAT strDate $30. ;

 FORMAT product best12. ;

 FORMAT sales nlnum12. ;

 INPUT

 strDate  $

 product

 sales

;

 

DATA new;

SET bakerysales;

dateSlashFinder=FIND(strDate,"/");

dateCommaFinder=INDEX(strDate, ',');

FORMAT productSales COMMA20.;

FORMAT productName $30.;

FORMAT date MMDDYY10.;

/* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: What is the if/else statement accomplishing? Your answer should be specific and complete, and describe (among other things) the purpose of the DO loop.*/

IF dateCommaFinder = 0 THEN

            DO

                date = input(strDate,MMDDYY10.);

                FORMAT date MMDDYY10.; 

        day = day(date);

        mnth=month(date);

        year=year(date);

            END;

ELSE

         DO 

              date3 = SUBSTR(strDate, dateCommaFinder+2);

              dateSpaceFinder=INDEX(date3, ' ');

              month = SUBSTR(date3, 1, dateSpaceFinder);

              SELECT (month);

                          WHEN ('January')           mnth=01;

                          WHEN ('February')          mnth=02;

                          WHEN ('March')             mnth=03;

                          WHEN ('April')             mnth=04;

                     WHEN ('May')               mnth=05;

                     WHEN ('June')              mnth=06;

                     WHEN ('July')              mnth=07;

                     WHEN ('August')            mnth=08;

                     WHEN ('September')         mnth=09;

                     WHEN ('October')           mnth=10;

                     WHEN ('November')          mnth=11;

                     WHEN ('December')          mnth=12;

                     OTHERWISE                  mnth=.;

                     END;

 

          day  = INPUT(SUBSTR(date3,dateSpaceFinder+1,2),2.);

          year = INPUT(SUBSTR(date3,dateSpaceFinder+5,4),4.);

          date = MDY(mnth,day,year);

       END;

 

/* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: What is the following section accomplishing? */

productSales = INPUT(TRIM(sales), COMMA20.);

SELECT (product);

   WHEN (1)                   productName='Breakfast bar';

   WHEN (2)                   productName='Cookie bar';

   WHEN (3)                   productName='Savory meal bar';

OTHERWISE                     productName=.;

END;

RUN;

 

/* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: What is the following section accomplishing? */

PROC TABULATE DATA = new FORMAT=DOLLAR11. STYLE={BACKGROUND=WHITE FOREGROUND=BLUE JUST=CENTER};

   CLASS productName  year mnth;

   VAR productSales;

   KEYLABEL ALL='Totals';

   TABLE productName = '' ALL, ((year='Year'*mnth='Month' ALL)*productSales='' *SUM='');

RUN;

8 REPLIES 8
PaigeMiller
Diamond | Level 26

This seems like a homework assignment, and you ought to at least try to answer the questions yourself, and we can help you if you get stuck, but we'd like to see what you have come up with on your own.

 

If you want to try something, you can try running the code without certain statements and see what happens. Then try running the code with those certain statements and see what the difference is.

--
Paige Miller
kerikae1
Calcite | Level 5

I did try however its my first time posting in the community, therefore base on the guidelines regarding asking for I thought I needed to posted the entire code that I was trying to run. My apologies 

PaigeMiller
Diamond | Level 26

Yes, you should post the code, but that wasn't my point. My point was that you should still try to do the homework yourself, you shouldn't expect us to do it for you. As I said, if you get stuck, we can help but we want to see some effort on your part to figure it out. I explained how you can try the code and see what it is doing.

--
Paige Miller
Reeza
Super User
The question isn't asking for any coding, it's asking you to explain what the relevant code sections do. You can try and answer them and we can critique your answers.
Reeza
Super User

This is a good homework or work assignment question IMO. It tests if you understand the code, because anyone can take the code and run it but only if you understand what's happening can you actually answer the questions.... I may have to employ this in our hiring exams :). 

 


@kerikae1 wrote:

 

Hi I am running this code but in the lines where I am ask to Replace the texts I can't seems to get it.....Not sure If i'm doing the right thing Just need some assistance in getting this code done ASAP!! Any help is appreciated  

 

DATA WORK.BAKERYSALES    ;

 INFILE '/home/emilymoore20/EPG194/output/myTestFolder/BSA570v4_Week4_assignment_data.txt' DELIMITER = '|' MISSOVER DSD LRECL=32767 FIRSTOBS=2 ;

 /* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: INFORMAT statements do what? */

 INFORMAT strDate $30. ;

 INFORMAT product best32. ;

 INFORMAT sales nlnum32. ;

 /* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: FORMAT statements do what? */

 FORMAT strDate $30. ;

 FORMAT product best12. ;

 FORMAT sales nlnum12. ;

 INPUT

 strDate  $

 product

 sales

;

 

DATA new;

SET bakerysales;

dateSlashFinder=FIND(strDate,"/");

dateCommaFinder=INDEX(strDate, ',');

FORMAT productSales COMMA20.;

FORMAT productName $30.;

FORMAT date MMDDYY10.;

/* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: What is the if/else statement accomplishing? Your answer should be specific and complete, and describe (among other things) the purpose of the DO loop.*/

IF dateCommaFinder = 0 THEN

            DO

                date = input(strDate,MMDDYY10.);

                FORMAT date MMDDYY10.; 

        day = day(date);

        mnth=month(date);

        year=year(date);

            END;

ELSE

         DO 

              date3 = SUBSTR(strDate, dateCommaFinder+2);

              dateSpaceFinder=INDEX(date3, ' ');

              month = SUBSTR(date3, 1, dateSpaceFinder);

              SELECT (month);

                          WHEN ('January')           mnth=01;

                          WHEN ('February')          mnth=02;

                          WHEN ('March')             mnth=03;

                          WHEN ('April')             mnth=04;

                     WHEN ('May')               mnth=05;

                     WHEN ('June')              mnth=06;

                     WHEN ('July')              mnth=07;

                     WHEN ('August')            mnth=08;

                     WHEN ('September')         mnth=09;

                     WHEN ('October')           mnth=10;

                     WHEN ('November')          mnth=11;

                     WHEN ('December')          mnth=12;

                     OTHERWISE                  mnth=.;

                     END;

 

          day  = INPUT(SUBSTR(date3,dateSpaceFinder+1,2),2.);

          year = INPUT(SUBSTR(date3,dateSpaceFinder+5,4),4.);

          date = MDY(mnth,day,year);

       END;

 

/* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: What is the following section accomplishing? */

productSales = INPUT(TRIM(sales), COMMA20.);

SELECT (product);

   WHEN (1)                   productName='Breakfast bar';

   WHEN (2)                   productName='Cookie bar';

   WHEN (3)                   productName='Savory meal bar';

OTHERWISE                     productName=.;

END;

RUN;

 

/* REPLACE THIS COMMENT TEXT TO ANSWER THE QUESTION: What is the following section accomplishing? */

PROC TABULATE DATA = new FORMAT=DOLLAR11. STYLE={BACKGROUND=WHITE FOREGROUND=BLUE JUST=CENTER};

   CLASS productName  year mnth;

   VAR productSales;

   KEYLABEL ALL='Totals';

   TABLE productName = '' ALL, ((year='Year'*mnth='Month' ALL)*productSales='' *SUM='');

RUN;


 

SASKiwi
PROC Star

@Reeza  - Agreed, getting potential hires to explain typical coding practices in their own words is a lot more insightful than doing quizzes IMO. 

Tom
Super User Tom
Super User

So the first two are easy.

Informats are instructions for how to convert text into values. Formats are instructions for how to convert values into text.  

In this program only the use of the NLNUM informat and format are necessary as SAS does not need special instructions for reading normal text or numbers and will default to displaying numbers using BEST12 format.

 

But the first INFORMAT statement also has a side effect of causing the compiler to define STRDATE as a character variable with a length of 30 bytes since this is the first place that it sees the variable referenced.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1344 views
  • 5 likes
  • 5 in conversation