I have a SAS dataset chapter5.pressure and i verified that it is fine by printing it proc print:
Obs SBPbefore SBPafter
1 120 128
2 124 131
3 130 131
4 118 127
5 140 132
6 128 125
7 140 141
8 135 137
9 126 118
10 130 132
11 126 129
12 127 135
So, I want to export it to the .dat file, and the following method does not work:
libname chapter5 'c:\users\owner\desktop\sas\chapter5';
data _null_;
set chapter5.pressure;
file 'c:\users\owner\desktop\sas\chapter5\xxx.dat';
put a b ;
run;
The resulting file has all missing values. Why
Try using the variable names instead of "a" and "b".
data _null_;
set chapter5.pressure;
file 'c:\users\owner\desktop\sas\chapter5\xxx.dat';
put SBPbefore SBPafter;
run;
Instead of using a put statement, you can also use PROC EXPORT to create a delimited file from a SAS dataset:
PROC EXPORT
DATA=chapter5.pressure
OUTFILE='c:\users\owner\desktop\sas\chapter5\xxx.dat'
DBMS=DLM
REPLACE;
RUN;
The default delimiter is a blank, which should match what you are trying to do. To create a tab or comma-delimited file, change the DBMS option value to TAB or CSV respectively. This will create a header row in the external file. Here is a link to the SAS 9.2 documentation. Check the SAS support site if you are using a different version.
Related
I'm writing SAS code and experiencing an error that seems to be caused by SAS generated language in code. I've been using SAS awhile and never experienced this. Any help/advice would be appreciated. I've cut out some of the middle code so this is not so long.
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program';
4 %LET _CLIENTPROJECTPATH='Z:\ACS\Decision Sciences\Analysis\Code\AAU_Analysis.egp';
5 %LET _CLIENTPROJECTNAME='AAU_Analysis.egp';
6 %LET _SASPROGRAMFILE=;
7
8 ODS _ALL_ CLOSE;
9 OPTIONS DEV=ACTIVEX;
10 FILENAME EGSR TEMP;
11 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
12 STYLE=HtmlBlue
13 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/6.1/Styles/HtmlBlue.css")
14 NOGTITLE
15 NOGFOOTNOTE
16 GPATH=&sasworklocation
17 ENCODING=UTF8
18 options(rolap="on")
19 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
20
21 options nomprint nomlogic;
22
23 libname acs 'F:\SAS_data\ACS';
NOTE: Libref ACS was successfully assigned as follows:
Engine: V9
Physical Name: F:\SAS_data\ACS
24 %include 'F:\SAS_data\Lysbet\sas_macro_library.sas';
171
173 %macro transform_survey;
174
175 data acs.aau_data_transformed;
176 set acs.aau_data;
177 length brand $3.;
189 %do i=1 %to 10;
190 antonym_pair=&i;
191 %do j = 1 %to &n;
192 %let val = %scan(&lst, &j);
193 brand=&val;
194 suppress_flag1=Q12&val.Flag1;
195 suppress_flag2=Q12&val.Flag2;
196 score=Q_12&val._&i;
197 output;
198 %end;
199 brand='ACS';
200 score=Q_9_&i;
201 output;
202 %end;
205 %mend;
206 %transform_survey;
207
208 %LET _CLIENTTASKLABEL=;
209 %LET _CLIENTPROJECTPATH=;
210 %LET _CLIENTPROJECTNAME=;
211 %LET _SASPROGRAMFILE=;
212
213 ;*';*";*/;quit;run;
____
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
That means somewhere (probably in the included macro library, or in previously submitted code) you have an unmatched quote (or unmatched %macro/%mend or other similar pair, but it looks like " if you have things lined up correctly).
Thanks for all input but classic case of user error. I forgot the run statement for the data step in my macro. I knew it was going to end up being something seemingly unrelated.
Even in proc sql I'm not using noexex then again why getting error.
same sql query in executed on hive and it give correct result no syntax error.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
58 disconnect from odbc;
NOTE: Statement not executed due to NOEXEC option.
"
proc sql ;
connect to odbc (dsn=inventory user=ashu password='');
create table libname.test_table as select
c0 format=11.,
c1 format=$30. length=30,
c2 format=11.,
c3 format=11.2
from connection to odbc
(SELECT c0,c1,c2,c3
FROM test_table
limit 10;);
disconnect from odbc;
quit ;
#superfluous #Joe complete log for same
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program';
4 %LET _CLIENTPROJECTPATH='C:\Users\goibibp-sas-admin\Desktop\In_Goibibo Reports\ingoibibo_inclusion.egp';
5 %LET _CLIENTPROJECTNAME='ingoibibo_inclusion.egp';
6 %LET _SASPROGRAMFILE=;
7
8 ODS _ALL_ CLOSE;
9 OPTIONS DEV=ACTIVEX;
10 GOPTIONS XPIXELS=0 YPIXELS=0;
11 FILENAME EGSR TEMP;
12 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
13 STYLE=HtmlBlue
14 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
15 NOGTITLE
16 NOGFOOTNOTE
17 GPATH=&sasworklocation
18 ENCODING=UTF8
19 options(rolap="on")
20 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
21
22 GOPTIONS ACCESSIBLE;
23 libname inibibo '/sasdata/sasdemo1/ingoibibo';
NOTE: Libref INIBIBO was successfully assigned as follows:
Engine: V9
Physical Name: /sasdata/sasdemo1/ingoibibo
24
25
26 proc sql;
27 connect to odbc (dsn=inventory user=goibibo password=XX);
ERROR: CLI error trying to establish connection: [unixODBC][DSI] The error message HardyHiveError could not be found in the en-US
locale. Check that /en-US/SimbaHiveODBCMessages.xml exists.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
28 create table inibibo.ingoibibo_inclusion as select
29 id format=11.,
30 inclusionname format=$50. length=50,
31 displayname format=$50. length=50,
32 rateplan_id format=11.,
33 inclusion_status format=$20. length=20,
34 rateplan_status format=$20. length=20
35 from connection to odbc
36 (SELECT inc.id, inc.inclusionname, inc.displayname, ri.rateplan_id,
37 (CASE WHEN inc.isactive = true THEN 'Active Inclusion' WHEN inc.isactive = false THEN 'Non Active Inclusion' END ) as
37 ! inclusion_status,
38 (CASE WHEN ri.inclusions_id = inc.id THEN 'With rate Plan'
39 WHEN ri.inclusions_id IS NULL THEN 'Without rate Plan' END) as rateplan_status
40 FROM goibibo_inventory.hotels_inclusions inc
41 LEFT JOIN goibibo_inventory.hotels_rateinclusions ri ON (ri.inclusions_id = inc.id ););
NOTE: Statement not executed due to NOEXEC option.
42 disconnect from odbc;
NOTE: Statement not executed due to NOEXEC option.
43 quit ;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds
2 The SAS System 16:29 Monday, May 9, 2016
44 /* creating index on exiting table
45 for more detail http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001395386.htm*/
46 /*proc sql;
47 create index createdon on inibibo.ingoibibo_hotel_booking(createdon);
48 quit;
49 */
50
51 /* remove table from LasR server if exist */
52 %macro lasrDeletedIfExists(lib,name);
53 %if %sysfunc(exist(&lib..&name.)) %then %do;
54 proc datasets library=&lib. nolist;
55 delete &name.;
56 quit;
57 %end;
58 %mend;
59
60 /* Load data in LasR */
61 /* inTable : reference of datasource table (lib.table) */
62 /* lasRTable : reference of target table in lasR server (lib.table) */
63 /* lasrLabel : label to use for the lasr Table (users description) */
64 %macro loadDataInLasR(inTable,lasRTable,lasrLabel);
65 proc options option=MEMSIZE;run;
66 data VALIBLA.&lasRTable (label=&lasrLabel);set inibibo.&inTable;run;
67 %mend;
68
69 /* Refresh metadata for the selected lasR table */
70 %macro updateMetadataForLasrTable(lasrLibref,mdsTargetFolder,lasrTableName);
71 proc metalib;
72 omr (LIBURI="SASLibrary?#libref='&lasrLibref'" );
73 /*no more used : update_rule=(delete);*/
74 report(type=summary);
75 folder="&mdsTargetFolder";
76 select=("&lasrTableName");
77 run;
78 %put PROC METALIB returned &SYSRC.;
79 %mend;
80
81
82
83 /* Access the LASR library */
84 LIBNAME VALIBLA SASIOLA TAG=HPS PORT=11001 HOST="nmclbi01.nm.ibibo.com"
84 ! SIGNER="http://nmclbi01.nm.ibibo.com:7080/SASLASRAuthorization" ;
NOTE: Libref VALIBLA was successfully assigned as follows:
Engine: SASIOLA
Physical Name: SAS LASR Analytic Server engine on local host, port 10011
85
86 /* remove table from memory if loaded in lasr server
87 * Param1 : LASR libref
88 * Param2 : LASR table name
89 */
90
91 %lasrDeletedIfExists(VALIBLA, ingoibibo_inclusion);
NOTE: Deleting VALIBLA.INGOIBIBO_INCLUSION (memtype=DATA).
NOTE: The table HPS.INGOIBIBO_INCLUSION has been removed from the SAS LASR Analytic Server.
NOTE: PROCEDURE DATASETS used (Total process time):
3 The SAS System 16:29 Monday, May 9, 2016
real time 0.70 seconds
cpu time 0.03 seconds
92
93
94 /* Load data in LasR
95 * Param1 : local table to read
96 * Param2 : LASR table to push (write) in LASR server
97 * Param3 : Label to use for user description on the table
98 */
99 %let etls_endtime = %sysfunc(datetime(), datetime20.);
100
101 %loadDataInLasR(ingoibibo_inclusion,ingoibibo_inclusion,Loaded on &etls_endtime.);
SAS (r) Proprietary Software Release 9.4 TS1M3
MEMSIZE=96745808640
Specifies the limit on the amount of virtual memory that can be used during a SAS session.
NOTE: PROCEDURE OPTIONS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: There were 45690 observations read from the data set INIBIBO.INGOIBIBO_INCLUSION.
NOTE: The data set VALIBLA.INGOIBIBO_INCLUSION has 45690 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 1.58 seconds
cpu time 0.05 seconds
102
103
104 /* Update metadata for the selected lasr table
105 * Param1 : LASR library libref
106 * Param2 : Target metadata server folder
107 * Param3 : LASR table name (only the table name, no libref)
108 */
109 %updateMetadataForLasrTable(VALIBLA,/Shared Data/SAS Visual Analytics/Public/LASR,ingoibibo_inclusion);
NOTE: A total of 1 tables were analyzed for library "Visual Analytics LASR".
NOTE: Metadata for 1 tables was updated.
NOTE: Metadata for 0 tables was added.
NOTE: Metadata for 0 tables matched the data sources.
NOTE: 0 tables listed in the SELECT or EXCLUDE statement were not found in either the metadata or the data source.
NOTE: 0 other tables were not processed due to error or UPDATE_RULE.
NOTE: PROCEDURE METALIB used (Total process time):
real time 1.96 seconds
cpu time 0.11 seconds
PROC METALIB returned 0
110
111
112 GOPTIONS NOACCESSIBLE;
113 %LET _CLIENTTASKLABEL=;
114 %LET _CLIENTPROJECTPATH=;
4 The SAS System 16:29 Monday, May 9, 2016
115 %LET _CLIENTPROJECTNAME=;
116 %LET _SASPROGRAMFILE=;
117
118 ;*';*";*/;quit;run;
119 ODS _ALL_ CLOSE;
120
121
122 QUIT; RUN;
Now I face same issue in all reports. before today all reports are running without error but suddenly error reflecting in all reports
NOEXEC is set when PROC SQL sees an error in an earlier step. It will then not execute any further lines of code, but it will check their syntax.
In this case, you'll need to look further up the log to see what's happened - either the connection attempt failed, or the select query failed.
Solution for same mention db name in proc sql query like dbname.tablename it will run with out error.
proc sql ;
connect to odbc (dsn=inventory user=ashu password='');
create table libname.test_table as select
c0 format=11.,
c1 format=$30. length=30,
c2 format=11.,
c3 format=11.2
from connection to odbc
(SELECT c0,c1,c2,c3
FROM db_name.test_table
limit 10;);
disconnect from odbc;
quit ;
Whenever I submit code in SAS University Edition, statements like this are inserted automatically and show up in the log:
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
What causes this, and is there a way to disable it? I'm not even sure whether these statements are doing anything, as all the associated content is still displayed in the log.
After following Dwal's suggestion below, here is all of the additional generated code:
1 OPTIONS NOSYNTAXCHECK;
2 TITLE;
3 FOOTNOTE;
4 OPTIONS LOCALE=en_US DFLANG=LOCALE;
5 DATA _NULL_;
6 VALUE=GETOPTION("VALIDVARNAME");
7 CALL SYMPUT("_WEBVVN", VALUE);
8 RUN;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
9 OPTIONS VALIDVARNAME=V7;
10 FILENAME _HTMLOUT TEMP;
11 FILENAME _GSFNAME TEMP;
12 FILENAME _DATAOUT TEMP;
13 %LET SYSCC=0;
14 %LET _CLIENTAPP=SAS Studio;
15 %LET _CLIENTAPPVERSION=3.3;
16 %LET _SASPROGRAMFILE = %BQUOTE();
17 %LET _BASEURL = %BQUOTE(http://localhost:10080/SASStudio/);
18 %LET _EXECENV=SASProgrammer;
19 DATA _NULL_;
20 CALL SYMPUT("GRAPHINIT","");
21 CALL SYMPUT("GRAPHTERM","");
22 RC=TSLVL('GEOCODE');
23 _ERROR_=0;
24 IF (RC^=' ') THEN DO;
25 CALL SYMPUT("GRAPHINIT","GOPTIONS RESET=ALL GSFNAME=_GSFNAME;");
26 CALL SYMPUT("GRAPHTERM","GOPTIONS NOACCESSIBLE;");
27 END;
28 RUN;
NOTE: Argument 1 to function TSLVL('GEOCODE') at line 22 column 4 is invalid.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
29 DATA _NULL_;
30 RC=SYSPROD("PRODNUM002");
31 IF (RC^=1) THEN DO;
32 CALL SYMPUT("GRAPHINIT","");
33 CALL SYMPUT("GRAPHTERM","");
34 END;
35 RUN;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
36 %LET _DATAOUT_MIME_TYPE=;
37 %LET _DATAOUT_NAME=;
38 %LET _DATAOUT_TABLE=;
39 %LET _DATAOUT_URL=;
40 %SYMDEL _DATAOUT_MIME_TYPE _DATAOUT_NAME _DATAOUT_URL _DATAOUT_TABLE;
41 %LET _SASWS_ = %BQUOTE(/folders/myfolders);
42 %LET _SASWSTEMP_=%BQUOTE(/folders/myfolders/.images/c1930fcb-2ffb-4ae0-8bfe-624b39b851b9);
43 ODS LISTING CLOSE;
44 OPTIONS PRINTERPATH=PDF;
45 ODS AUTONAVIGATE OFF;
46 ODS GRAPHICS ON;
47 ODS HTML5 (ID=WEB) DEVICE=PNG GPATH="&_SASWSTEMP_" ENCODING=utf8 FILE=_HTMLOUT (TITLE='Results: Program') STYLE=Htmlblue
47 ! OPTIONS(BITMAP_MODE='INLINE' SVG_MODE='INLINE' CSS_PREFIX='.ods_c1930fcb-2ffb-4ae0-8bfe-624b39b851b9'
47 ! BODY_ID='div_c1930fcb-2ffb-4ae0-8bfe-624b39b851b9' );
NOTE: Writing HTML5(WEB) Body file: _HTMLOUT
48 &GRAPHINIT;
49 OPTIONS FIRSTOBS=1;
50 OPTIONS OBS=MAX;
51 OPTIONS DTRESET DATE NUMBER NOTES;
52 OPTIONS NOSYNTAXCHECK;
53
The bit I actually submitted:
54 data _null_;
55 put "Hello";
56 run;
Hello
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
And then some more afterwards:
57
58 OPTIONS NOSYNTAXCHECK;
59 ODS HTML CLOSE;
60 &GRAPHTERM; ;*';*";*/;RUN;QUIT;
61 QUIT;RUN;
62 OPTIONS VALIDVARNAME=&_WEBVVN;
63 %SYMDEL _WEBVVN;
64 ODS HTML5 (ID=WEB) CLOSE;
65
66 FILENAME _GSFNAME;
NOTE: Fileref _GSFNAME has been deassigned.
67 DATA _NULL_;RUN;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
67 ! OPTIONS NOTES STIMER SOURCE SYNTAXCHECK;
68
There's several places that options can be set in SAS - the below list are in order of precedence (ie #1 supercedes #2 etc):
Restricted options table, if it exists (if you're on a university sever these may have been set)
OPTIONS statement (or SAS System Options window)
Autoexec file (that contains an OPTIONS statement)
Command-line specification
Configuration file specification
SAS system default settings.
You can check the actual values of these options by sumbitting the following which will output a list of all the system options and their current values:
proc options define ;
run ;
From what you're saying, it sounds like the log is still outputing notes/source lines yes? If your seeing OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; in your log then it's just a guess but it could be that the statement is coming from an autoexec file (#3) which is then being superceded by unitversity restricted options (#1).
You can check this from the output of the proc options statement above by looking for the value of the AUTOEXEC option as this will specify the path to the autoexec file being submitted (if there is one).
I am new to SAS, so this might be a silly type of question.
Assume there are several datasets with similar structure but different column names. I want to get new datasets with the same number of rows but only a subset of columns.
In the following example, Data_A and Data_B are original datasets and SubA and SubBare what I want. What is the efficient way of deriving SubA and SubB?
DATA A_auto;
LENGTH A_make $ 20;
INPUT A_make $ 1-17 A_price A_mpg A_rep78 A_hdroom A_trunk A_weight A_length A_turn A_displ A_gratio A_foreign;
CARDS;
AMC Concord 4099 22 3 2.5 11 2930 186 40 121 3.58 0
AMC Pacer 4749 17 3 3.0 11 3350 173 40 258 2.53 0
Audi Fox 6295 23 3 2.5 11 2070 174 36 97 3.70 1
;
RUN;
DATA B_auto;
LENGTH make $ 20;
INPUT B_make $ 1-17 B_price B_mpg B_rep78 B_hdroom B_trunk B_weight B_length B_turn B_displ B_gratio B_foreign;
CARDS;
Toyota Celica 5899 18 5 2.5 14 2410 174 36 134 3.06 1
Toyota Corolla 3748 31 5 3.0 9 2200 165 35 97 3.21 1
VW Scirocco 6850 25 4 2.0 16 1990 156 36 97 3.78 1
;
RUN;
DATA SubA;
set A_auto;
keep A_make A_price;
RUN;
DATA SubB;
set B_auto;
keep B_make B_price;
RUN;
Here's my new answer. This introduces quite a few concepts, but all are necessary to complete this task.
First of all I would store the required part variable names (the suffixes that are common to all datasets) in a new dataset. This keeps them all in one place and makes it easier to change if required.
The next step is to create a regular expression (regex) search string that combines all the names, separated by a pipe (|), which is the regex symbol for or. I've also added a $ symbol to end of the names, this ensures only variables ending with the part names will be selected.
select into :[macroname] is the method to create macro variables within proc sql
Then I set up a macro to extract the specific variable names for the current dataset and use those names to create a view (like my original answer)
The dictionary library referenced in the proc sql is a metadata library that contains information on all active libraries, tables, columns etc, so is a good source of identifying what the actual variable names are called (based on the regex search string created earlier).
You won't need the proc print in your code, I just put it in to show everything is working as expected.
Let me know if this works for you
/* create intial datasets */
DATA A_auto;
LENGTH A_make $ 20;
INPUT A_make $ 1-17 A_price A_mpg A_rep78 A_hdroom A_trunk A_weight A_length A_turn A_displ A_gratio A_foreign;
CARDS;
AMC Concord 4099 22 3 2.5 11 2930 186 40 121 3.58 0
AMC Pacer 4749 17 3 3.0 11 3350 173 40 258 2.53 0
Audi Fox 6295 23 3 2.5 11 2070 174 36 97 3.70 1
;
RUN;
DATA B_auto;
LENGTH B_make $ 20;
INPUT B_make $ 1-17 B_price B_mpg B_rep78 B_hdroom B_trunk B_weight B_length B_turn B_displ B_gratio B_foreign;
CARDS;
Toyota Celica 5899 18 5 2.5 14 2410 174 36 134 3.06 1
Toyota Corolla 3748 31 5 3.0 9 2200 165 35 97 3.21 1
VW Scirocco 6850 25 4 2.0 16 1990 156 36 97 3.78 1
;
RUN;
/* create dataset containing partial name of variables to keep */
data keepvars;
input part_name $ :20.;
datalines;
_make
_price
;
run;
/* create regular expression search string from partial names */
proc sql noprint;
select
cats(part_name,'$') /* '$' matches end of string */
into
:name_str separated by '|' /* '|' is an 'or' search operator in regular expressions */
from
keepvars;
quit;
%put &name_str.; /* print search string to log */
/* macro to create views from datasets */
%macro create_views (dsname, vwname); /* inputs are dataset name being read in and view name being created */
/* extract specific variable names to be kept, based on search string */
proc sql noprint;
select
name
into
:vars separated by ' '
from
dictionary.columns
where
libname = 'WORK'
and memname = upper("&dsname.")
and prxmatch("/&name_str./",strip(name))>0; /* prxmatch is regular expression search function */
quit;
%put &vars.; /* print variables to keep to log */
/* create views */
data &vwname. / view=&vwname.;
set &dsname. (keep=&vars.);
run;
/* test view by printing */
proc print data=&vwname.;;
run;
%mend create_views;
/* run macro for each dataset */
%create_views(A_auto, SubA);
%create_views(B_auto, SubB);
I have a dataset that looks like this, and am using SAS Enterprise Guide 6.3:
data have;
input id state $;
cards;
134 NC,NY,SC
145 AL,NC,NY,SC
;
run;
I have another dataset that has several metrics for each id in every state, but I only need to pull the data for the states listed in the second column of the have dataset.
data complete;
input id state $ metric;
cards;
134 AL 5
134 NC 4.3
134 NY 4
134 SC 5.5
145 AL 1.3
145 NC 1.3
145 NY 1.5
145 SC 1.1
177 AL 10
177 NC 74
177 NY 23
177 SC 33
;
run;
I thought about using trnwrd to replace the comma with ', ' and concatenating a beginning and ending quote to make the list a character list, so that I could use a WHERE IN statement. However, I think it would be more helpful if I could somehow transpose the comma separated list to something like this:
data have_mod;
input id state $;
cards;
134 NC
134 NY
134 SC
145 AL
145 NC
145 NY
145 SC
;
run;
Then I could simply join this table to the complete data table to get the subset I need (below).
data want;
input id state $ metric;
cards;
134 NC 4.3
134 NY 4
134 SC 5.5
145 AL 1.3
145 NC 1.3
145 NY 1.5
145 SC 1.1
;
run;
Any thoughts? Thanks.
I'd do exactly what you propose and transpose it - except i'd read it in that way.
data have;
infile datalines truncover dlm=', ';
length state $2;
input id #; *read in the id for that line;
do until (state=''); *keep reading in until state is missing = EOL;
input state $ #;
if not missing(state) then output;
end;
cards;
134 NC,NY,SC
145 AL,NC,NY,SC
;
run;
Alternately, you can SCAN for the first statecode.
data want_to_merge;
set have;
state_first = scan(state,1,',');
run;
SCAN is the function equivalent of reading in a delimited file.