I am using sas studio in the SAS OnDemand for academics,
I imported cvs file to sas table
I want to produce 2 new tables for men and woman, but when I use the following code I get no observations in the mens output table and the original data set in the females output table
This is the code I used:
/* Código generado (IMPORT) */
/* Archivo de origen: tsdem.csv */
/* Ruta de origen: /home/tessygsv0/ECOPRED CSV */
/* Código generado el: 29/1/19 15:17 */
%web_drop_table(WORK.TSDEM);
FILENAME REFFILE '/home/tessygsv0/ECOPRED CSV/tsdem.csv';
PROC IMPORT DATAFILE=REFFILE
DBMS=CSV
OUT=WORK.TSDEM;
GETNAMES=YES;
RUN;
PROC CONTENTS DATA=WORK.TSDEM; RUN;
%web_open_table(WORK.TSDEM);
This the code which is not working:
data hombres mujeres;
set work.TSDEM;
if SEXO='1' then output hombres;
else output mujeres;
run;
Hi Tessy
Your if-then-else-construct writes to the mujeres-dataset, if variable SEXO is empty or anything but '1' . Are you sure that your import works as expected, so you actually get value '1' for hombres? - Try making a Proc print and see what you get.
That error has nothing to do with your code.
SAS is complaining about the setting for the LOCALE option.
4 OPTIONS LOCALE=es_419 DFLANG=LOCALE; ______ 14 ERROR 14-12: Invalid option value ES_419 for SAS option LOCALE.
Check and see if there is an option or preference setting in SAS/Studio that will let you change that so that SAS/Studio doesn't try to send SAS and invalid value.
In general you rarely need to split your data set, instead use By statements. See the sample below. If you want to get your code working, please post the log from your code.
proc sort data=tsdem;
by sexo;
run;
proc freq data=tsdem;
table sexo;
run;
proc print data=tsdem;
by sexo;
run;
proc means data=TSDEM;
by sexo;
run;
@Tessy wrote:
I am using sas studio in the SAS OnDemand for academics,
I imported cvs file to sas table
I want to produce 2 new tables for men and woman, but when I use the following code I get no observations in the mens output table and the original data set in the females output table
This is the code I used:
/* Código generado (IMPORT) */
/* Archivo de origen: tsdem.csv */
/* Ruta de origen: /home/tessygsv0/ECOPRED CSV */
/* Código generado el: 29/1/19 15:17 */%web_drop_table(WORK.TSDEM);
FILENAME REFFILE '/home/tessygsv0/ECOPRED CSV/tsdem.csv';PROC IMPORT DATAFILE=REFFILE
DBMS=CSV
OUT=WORK.TSDEM;
GETNAMES=YES;
RUN;PROC CONTENTS DATA=WORK.TSDEM; RUN;
%web_open_table(WORK.TSDEM);
This the code which is not working:
data hombres mujeres;
set work.TSDEM;
if SEXO='1' then output hombres;
else output mujeres;
run;
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.