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

How do I import a csv file into the library or is it possible? 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

1) If the AGE is a group given as "18-50" then use

    where age = "18-50"; 

     If AGE is a number like 25 then you can use

     where age between 18 and 50;

 

2) The title of your post is "How do I import a CSV file into the SAS library".

     You got the solution to your question.

 

    The new post dealing how to subset your date according to age group

    should be posted as a new query.

 

View solution in original post

16 REPLIES 16
Kimberly_2020
Calcite | Level 5

My end goal is to create a frequency table..it lets me enter the source of the data but the data set is not showing up in the library 

Shmuel
Garnet | Level 18

You can use either proc import:

proc import file="Path_and_FileName.csv"
            out=test dbms=csv 
            replace;
     getnames=yes;  /* assume first line contains variable names */
run;

Try it and if any issue post the full log showing your code and messages.

Depending on data types you may have issues especially getting the wrong type.

If possible post also a sample lines from the csv file.

 

 

Kimberly_2020
Calcite | Level 5

I have it now. I need a frequency table for an age group (18-50) along with gender 

proc freq data=WORK.SYPHILIS;
	tables genderC genderB age / plots=(freqplot cumfreqplot);
run;

How do I write the code for an age group of 18-50

Reeza
Super User
You add a WHERE statement to filter out/in the groups you want.

WHERE age_group = '18 to 50';
Kimberly_2020
Calcite | Level 5
proc freq data=WORK.SYPHILIS;
	tables age sex_o genderC genderB / plots=(freqplot cumfreqplot);
	where age_group= '18 to 50';
run;

Log: 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         /*
 74          *
 75          * Task code generated by SAS Studio 3.8
 76          *
 77          * Generated on '8/5/20, 12:06 PM'
 78          * Generated by 'u49152646'
 79          * Generated on server 'ODAWS02-USW2.ODA.SAS.COM'
 80          * Generated on SAS platform 'Linux LIN X64 3.10.0-1062.9.1.el7.x86_64'
 81          * Generated on SAS version '9.04.01M6P11072018'
 82          * Generated on browser 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
 82       ! Chrome/84.0.4147.105 Safari/537.36'
 83          * Generated on web client
 83       ! 'https://odamid-usw2.oda.sas.com/SASStudio/main?locale=en_US&zone=GMT-07%253A00&ticket=ST-58631-NKEgz3Gaqesii60Jleii-cas'
 84          *
 85          */
 86         
 87         proc freq data=WORK.SYPHILIS;
 88         tables age sex_o genderC genderB / plots=(freqplot cumfreqplot);
 89         where age_group= '18 to 50';
 ERROR: Variable age_group is not on file WORK.SYPHILIS.
 90         run;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE FREQ used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              1375.50k
       OS Memory           38572.00k
       Timestamp           08/05/2020 07:33:34 PM
       Step Count                        265  Switch Count  0
       Page Faults                       0
       Page Reclaims                     242
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 91         
 92         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 104        
Kimberly_2020
Calcite | Level 5

It says that the age_group is not on the work.syphilis file. Where did I go wrong? 

Shmuel
Garnet | Level 18

Your variable is named age. What kind of values does it contain?

The WHERE statement may be either

where age is between 18 and 50

 

or

where age is "18 to 50"

 

depending on age variable  - is it an age of a person or

is it a group age/

Kimberly_2020
Calcite | Level 5

It is a group age...(Age of people between the age of 18 and 50) 

I got a frequency table from age 18-50....but I didn't use the word "is"..Does it matter 


 


proc freq data=WORK.SYPHILIS;
	tables age sex_o genderC genderB RACE / plots=(freqplot cumfreqplot);
	where age between 18 and 50;
run;
Reeza
Super User
We don't have your data so can only guess at what you're asking...if you need specific help you need to provide sample data.
Shmuel
Garnet | Level 18

1) If the AGE is a group given as "18-50" then use

    where age = "18-50"; 

     If AGE is a number like 25 then you can use

     where age between 18 and 50;

 

2) The title of your post is "How do I import a CSV file into the SAS library".

     You got the solution to your question.

 

    The new post dealing how to subset your date according to age group

    should be posted as a new query.

 

Kimberly_2020
Calcite | Level 5

Attached is my data. Again, my where statement was:

 

where age between 18 and 50

Kimberly_2020
Calcite | Level 5

This is what it says: 

 

proc freq data=WORK.SYPHILIS;
	tables age sex_o genderC genderB / plots=(freqplot cumfreqplot);
	where age_group= '18 to 50';
run;

Log: 

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         /*
 74          *
 75          * Task code generated by SAS Studio 3.8
 76          *
 77          * Generated on '8/5/20, 12:06 PM'
 78          * Generated by 'u49152646'
 79          * Generated on server 'ODAWS02-USW2.ODA.SAS.COM'
 80          * Generated on SAS platform 'Linux LIN X64 3.10.0-1062.9.1.el7.x86_64'
 81          * Generated on SAS version '9.04.01M6P11072018'
 82          * Generated on browser 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
 82       ! Chrome/84.0.4147.105 Safari/537.36'
 83          * Generated on web client
 83       ! 'https://odamid-usw2.oda.sas.com/SASStudio/main?locale=en_US&zone=GMT-07%253A00&ticket=ST-58631-NKEgz3Gaqesii60Jleii-cas'
 84          *
 85          */
 86         
 87         proc freq data=WORK.SYPHILIS;
 88         tables age sex_o genderC genderB / plots=(freqplot cumfreqplot);
 89         where age_group= '18 to 50';
 ERROR: Variable age_group is not on file WORK.SYPHILIS.
 90         run;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE FREQ used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              1375.50k
       OS Memory           38572.00k
       Timestamp           08/05/2020 07:33:34 PM
       Step Count                        265  Switch Count  0
       Page Faults                       0
       Page Reclaims                     242
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           0
       
 91         
 92         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 104        
Kimberly_2020
Calcite | Level 5

I figured it out..I did where age between 19 and 50;

Reeza
Super User
Yes it's possible. Use an Import Data task is likely your best bet if you're unfamiliar with SAS.
Or use PROC IMPORT. That creates a SAS data set that can then be worked with in SAS.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 16 replies
  • 4736 views
  • 0 likes
  • 3 in conversation